Transparency on Picturebox's in C#

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! I'm making a small program and on that program i am loading a picturebox with an image, this image has a black background. How would i make so that all the black pixel's will be fully transparent? I've tried everything but i can't make any progress. Thanks, Hepy

Share on other sites
Huh, it's says i've had a reply but when i click on it there's nothing there?
Any Ideas ?
Thanks,
Hepy

[Edited by - Hepy on January 2, 2005 10:43:10 AM]

Share on other sites
Something like this worked for me:

            Bitmap bmp = (Bitmap)Image.FromFile( @"T:\fenn_black.bmp" );            bmp.MakeTransparent( Color.FromArgb( 0, 0, 0 ) ); // (0, 0, 0) is black            this.pictureBox1.Image = bmp;

Share on other sites
Hi, thanks for the reply. When i try my code and your code mixed:

            {                //adding the control                PictureBox pic = new PictureBox();                tabPage1.Controls.Add(pic);                                //defining the control                 Bitmap bmp = (Bitmap)Image.FromFile(path);                bmp.MakeTransparent(Color.FromArgb(0, 0, 0));                pic.Image = bmp;                pic.Left = 40;                pic.Top = 40;                pic.BringToFront();                pic.AutoSize = false;                pic.Top = mousey;                pic.Left = mousex;                pic.Name = CtrlName.Text;                pic.Cursor = Cursors.No;                mouseclik = 0;            }

I get the following results (note: the background of the sprite is normally black.)

Thanks for any help,
Hepy

Share on other sites
From your code, it looks like you're creating several seperate PictureBox controls rather than painting an image in several places on one PictureBox control. The transparency of the image contained in the PictureBox is only relevant when blending with other images in the same PictureBox.

To achieve the effect that I think you want, you should paint the same picture in several places on one PictureBox. You can do that using a System.Drawing.Graphics object. You will probably need to override the OnPaint() method of your form/control to repaint the images when the region is invalidated, which means you will have to store their locations as something similar to an ArrayList of Point objects.

Share on other sites
Yes, but this wouldn't work as i need to move the images around in realtime. Thus, needing to keep them in different pictures boxes.
any ideas, Hepy