Results 1 to 6 of 6

Thread: How to make transparent buttons in C#

  1. #1
    Join Date
    Nov 2008
    Posts
    866

    How to make transparent buttons in C#

    I make my own buttons with pictureBox. They should be round and drag only, and is fine to look to.

    But I am unable to transparent device to work. I use MakeTrasparent to make a color transparent. The problem is that color is not transparent, but the same as the background color of the form. Is there something wrong, or have I just misunderstood?

    Code:
    Bitmap b = new Bitmap (recorderButtonPic.Image); 
    Color t = b.GetPixel (1, 1); 
    b.MakeTransparent (t); 
    recorderButtonPic.Image = b;

  2. #2
    Join Date
    May 2008
    Posts
    913

    Re: How to make transparent buttons in C#

    Do not set this property on Bitmap. Just when you make a Bitmap without an Alpha channel, select a color mask.

    Use Form.TransparencyKey instead.

  3. #3
    Join Date
    Nov 2008
    Posts
    866

    Re: How to make transparent buttons in C#

    Is it the way you think:

    Code:
    Bitmap b = new Bitmap (recorderButtonPic.Image); 
    b.MakeTransparent (TPC.ActiveForm.TransparencyKey); 
    recorderButtonPic.Image = b;
    Isn't that the same.

  4. #4
    Join Date
    May 2008
    Posts
    913

    Re: How to make transparent buttons in C#

    You made a mistake my friend. This will give an error.

    Code:
    TCP.ActiveForm.TransparencyKey = Color.Magenta
    Afterwards, you can draw the shape, just set Image property of the Bitmap you have made.

    You can change TCP.ActiveForm.TransparencyKey to [Bitmap].GetPixel (0, 0) if you wish.

    MakeTransparent is to set a transparent color on a bitmap, that you do not need to do in this case.

  5. #5
    Join Date
    Nov 2008
    Posts
    866

    Re: How to make transparent buttons in C#

    So is that correct now:

    Code:
    Form.ActiveForm.TransparencyKey = Form.ActiveForm.BackColor;
    Unfortunately it gives an exception:

    Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.

  6. #6
    Join Date
    May 2008
    Posts
    913

    Re: How to make transparent buttons in C#

    Choose the form in the editor, and select TransparencyKey property, and select Color.Control instead. If that does not help to put PictureBox.BackColor to Color.Transparent, you must declare a separate class:

    Code:
    class MyTransparentPictureBox : PictureBox 
    {
    public override CreateParams CreateParams 
    {
    get {CreateParam param = base.CreateParams; param.ExStyle | = 0x00000020; return param;}
    }
    }

Similar Threads

  1. How To Make Image Transparent in GIMP?
    By Landry in forum Customize Desktop
    Replies: 6
    Last Post: 22-08-2011, 01:20 PM
  2. How to make bmp image transparent
    By SMG in forum Windows Software
    Replies: 7
    Last Post: 27-08-2010, 05:17 PM
  3. How to make Windows XP taskbar Transparent ?
    By Demi in forum Customize Desktop
    Replies: 3
    Last Post: 25-06-2009, 11:30 PM
  4. How to make an IFrame transparent?
    By Sachit in forum Software Development
    Replies: 3
    Last Post: 13-02-2009, 08:44 PM
  5. How to make a transparent form in VB 6.0
    By CheckMeNot in forum Software Development
    Replies: 2
    Last Post: 24-12-2008, 02:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,033,484.63687 seconds with 17 queries