Displaying a picture with Transparent Background

Dear ppl,

I have a .bmp picture with transparent background..but when i display it on the form using a picture box, the area that should suppose to be transparent is being displayed as the background color of the picture box. Even if i set the picture box background color to transparent , it doesn't make any difference.

So I created a user control and override the onpaint() method to draw the picture using the imageAttribute SetKeyColor() method, but that is not working as well....what is happening is the picture is being displayed properly with transparent area not being displayed, instead the transparent area is being painted as the backcolor of the usercontrol...even if i set the back color of the usercontrol to transparent it doesn't make any difference.

So i created a usercontrol inhereting from pictureBox control...I override the onPaint() method ..now what is happeing is... in the area of the picture where it is transparent, its totally transparent meaning the PDA desktop is being displayed in the transparent areas instead of the parent form area which contains the picture box.

Desperate Help required




Answer this question

Displaying a picture with Transparent Background

  • Charles Tam

    Here is my control

    class MyPictureBox : PictureBox

    {

    void MyPictureBox()

    {

    this.BackColor = Color.Transparent;

    }

    protected override void OnPaint(PaintEventArgs e)

    {

    if (this.Image != null)

    {

    Bitmap bmp = new Bitmap(this.Image);

    ImageAttributes attr = new ImageAttributes();:

    attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0));

    Rectangle dstRect = new Rectangle(0, 0, bmp.Width, bmp.Height);

    e.Graphics.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height,

    GraphicsUnit.Pixel, attr);

    }

    else

    base.OnPaint(e);

    }

    }



  • JohanK

    I'm no expert but I've seen this question asked a lot.

    I believe transparency isn't supported in WindowsCE. Have you tried a search for transparent on the forums you may find what you are looking for.

  • Ivana Hudakova

    yeah i have found this http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=163606&SiteID=1

    btu i have already tried this..its not workign....I can't understand y



  • Displaying a picture with Transparent Background