Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-12-2008
Member
 
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;
Reply With Quote
  #2  
Old 01-12-2008
Member
 
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.
Reply With Quote
  #3  
Old 01-12-2008
Member
 
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.
Reply With Quote
  #4  
Old 01-12-2008
Member
 
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.
Reply With Quote
  #5  
Old 01-12-2008
Member
 
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:

Quote:
Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
Reply With Quote
  #6  
Old 01-12-2008
Member
 
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;}
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to make transparent buttons in C#"
Thread Thread Starter Forum Replies Last Post
How To Make Image Transparent in GIMP? Landry Customize Desktop 6 22-08-2011 01:20 PM
How to make bmp image transparent SMG Windows Software 7 27-08-2010 05:17 PM
How to make Windows XP taskbar Transparent ? Demi Customize Desktop 3 25-06-2009 11:30 PM
How to make an IFrame transparent? Sachit Software Development 3 13-02-2009 08:44 PM
How to make a transparent form in VB 6.0 CheckMeNot Software Development 2 24-12-2008 02:27 PM


All times are GMT +5.5. The time now is 05:24 PM.