Codelog

foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }

Transparent images over controls

with one comment

Before me starting off with the article, sorry for not posting anything last week. I was kinna busy with the office works :P 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

not_so_transparent

Way that you may be interested to know about

  • Add a button to your applicationReally transparent image


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
}

Written by sudarsanyes

August 14th, 2008 at 10:43 am

Posted in C#, Controls, UI

Tagged with , ,

One Response to 'Transparent images over controls'

Subscribe to comments with RSS or TrackBack to 'Transparent images over controls'.

  1. 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

Leave a Reply