Transparent images over controls
Before me starting off with the article, sorry for not posting anything last week. I was kinna busy with the office works
Hmm. Lets begin.
Have you ever tried to put a transparent image over a button or some other control ?? I meant transparent. If not, lets try it.
Way that may not give you the solution you need
- Add a button in to you application
- Drag a picturebox
- Import an image in to the picturebox (for the one who dosen’t know how to do it programaticall — refer here !!)
- Make the picturebox’s background transparent (use the property Background
- Does it look really transparent ?? (See the control’s — image’s background !!)
Way that you may be interested to know about
System.Windows.Forms.Button myTransparentImageButton = new System.Windows.Forms.Button();
this.Controls.Add(myTransparentImageButton);
- For the picture … do we need a picturebox to put the image ?? No. Lets try to draw the image over the button.
- Import an image to the resource file and add the following snippet to the paint event of the button
private void myTransparentImageButton_Paint(object sender, PaintEventArgs e) //Handling the
paintevent as the image should be painted over the button when the button is painted
{
Graphics aGraphics = e.Graphics; //To draw the image, we use the abstract class -- Graphics
Image aImage = (Image)<your_name_space>.<resource_file_class_name>.<image>; //Creating an
image object using the bitmap from the resource file
aGraphics.DrawImage(aImage, new Point(e.ClipRectangle.Width - aImage.Width, 0)); //Drawing the
image in the required position
}




Great to have you back. Now that reminds me of posting about the IE’s transparent PNG image hack.
cnu
14 Aug 08 at 12:29 pm