Click here to Skip to main content
15,881,967 members
Articles / Multimedia / GDI+
Article

Iconits

Rate me:
Please Sign up or sign in to vote.
4.69/5 (75 votes)
12 Apr 20062 min read 218.2K   3.6K   209   49
An icon control that zooms and fades-in when your mouse hovers over it, which creates interesting visual effects if your application uses icons instead of buttons.

Sample Image

Introduction

For an application that uses icons instead of buttons, perhaps there might be a need to add some fancy effects rather than only showing a rising icon (when hovering). This control gives you an interesting visual effect, which makes an icon to zoom when the mouse hovers over it. Also, there is a Blur property that will cause the icon to be rendered transparent (without a single line of code!); of course, you may turn it off.

Usage

You can start using this control by following these two simple steps:

  1. Add the control to the toolbox (if you don't know how to do it, right click on the Toolbox, choose Add/Remove items, find Iconits.dll, and press OK).
  2. Now that you have seen the control on the toolbox (Iconits), you can start using it. However, these properties are essential:
    Property nameTypeDescription
    BlurBooleanSet to true if you want the transparency effect, set to false otherwise.
    IconBitmapSet the icon from any available image.
    IconSizeSizeIcon initial size.
    SizeSizeIcon actual size when mouse hovers over it.
    TooltipTextStringIcon's tooltip text which pops up when the mouse hovers over it for some seconds.

Alpha class

The trick on how the image becomes slightly transparent is done by creating three additional bitmaps instead of the original image. These additional bitmaps, with different opacity (0.25, 0.5, 0.75), will make the effect of the icon slightly fading.

The idea of generating bitmaps instead of direct rendering is, of course, speed. Another reason is, only three images are necessary and that is not too much. So, we develop a class which generates a new bitmap with a different opacity level from the available image:

C#
public static Bitmap returnAlpha(Bitmap bmp, int alpha)
{
    Color col; 
    Bitmap bmp2=new Bitmap(bmp);
    
    for (int i=0;i<bmp.Width;i++)
          for (int j=0;j<bmp.Height;j++) 
          {
            col=bmp.GetPixel(i,j); 
            if (col.A>0)
                bmp2.SetPixel(i,j,Color.FromArgb(min(
                       col.A-alpha),col.R,col.G,col.B)); 
          } 
      return bmp2;
}

It simply iterates through the image and redraws the image with a new transparency level, and, of course, you don't need to redraw the pixel which is already transparent (Alpha=0).

Optimization Issues

Optimization is a critical issue when you develop such controls that employ heavy computations. In this case, the problems are speed and image flickering since GDI+'s DrawImage is used. Double buffering is implemented so that the animation will displayed smoothly. Another issue, slow speed, only occurs if you do a direct rendering of the transparent image. We build additional bitmaps for this reason, which causes another drawback, the use of additional memory.

History

  • v0.1 (9 April 2006): Initial release.

    Implemented alpha transparency, and zoom on mouse-hover.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Indonesia Indonesia
Yojana Hanif was love to code, he is just graduated from Institut Teknologi Sepuluh Nopember Surabaya Indonesia.

Comments and Discussions

 
GeneralRe: A more efficient alpha routeen... Pin
mrsnipey8-May-06 16:56
mrsnipey8-May-06 16:56 
GeneralJayoscar : Your code has C# syntax violations and errors Pin
BillWoodruff24-Apr-06 20:39
professionalBillWoodruff24-Apr-06 20:39 
GeneralRe: A more efficient alpha routeen... Pin
Mc Gwyn11-Aug-06 8:10
Mc Gwyn11-Aug-06 8:10 
QuestionRe: A more efficient alpha routeen... Pin
gordingin19-Nov-06 3:45
gordingin19-Nov-06 3:45 
Generala few minor errors in Rista's alpha mod code ... Pin
BillWoodruff24-Apr-06 21:42
professionalBillWoodruff24-Apr-06 21:42 
GeneralRe: a few minor errors in Rista's alpha mod code ... Pin
Jon Rista25-Apr-06 9:39
Jon Rista25-Apr-06 9:39 
GeneralAwe-some !!! Pin
Babu Aboobacker E.I20-Apr-06 10:29
Babu Aboobacker E.I20-Apr-06 10:29 
GeneralVery Nice Pin
Santosh K Sahoo18-Apr-06 19:13
Santosh K Sahoo18-Apr-06 19:13 
Thank you very much, for an excellent piece of code

Regards,
Santosh Ku Sahoo
GeneralNow this IS good Pin
Obaid ur Rehman18-Apr-06 13:47
Obaid ur Rehman18-Apr-06 13:47 
GeneralVery Nice but... Pin
Gavin Roberts12-Apr-06 23:38
Gavin Roberts12-Apr-06 23:38 
GeneralRe: Very Nice but... Pin
Christopher Pearce12-Apr-06 23:58
Christopher Pearce12-Apr-06 23:58 
GeneralRe: Very Nice but... Pin
Josh Smith13-Apr-06 1:54
Josh Smith13-Apr-06 1:54 
GeneralRe: Very Nice but... Pin
Christopher Pearce13-Apr-06 1:55
Christopher Pearce13-Apr-06 1:55 
GeneralRe: Very Nice but... Pin
hanifku13-Apr-06 4:42
hanifku13-Apr-06 4:42 
GeneralRe: Very Nice but... Pin
[Marc]15-Apr-06 12:56
[Marc]15-Apr-06 12:56 
GeneralRe: Very Nice but... Pin
David Fleming18-Apr-06 9:42
David Fleming18-Apr-06 9:42 
GeneralRe: Very Nice but... Pin
CarpeDiem_TF24-Jun-08 18:07
CarpeDiem_TF24-Jun-08 18:07 
GeneralRe: Very Nice but... Pin
Nick Z.18-Apr-06 10:57
Nick Z.18-Apr-06 10:57 
GeneralRe: Very Nice but... Pin
rizwan8221-Apr-06 2:12
rizwan8221-Apr-06 2:12 
GeneralWow! Pin
Alessio.NET12-Apr-06 21:45
Alessio.NET12-Apr-06 21:45 
GeneralKool Animation Pin
M@dHatter12-Apr-06 19:46
M@dHatter12-Apr-06 19:46 
Generalthis iz... Pin
Jouledoc12-Apr-06 17:20
Jouledoc12-Apr-06 17:20 
GeneralExcellent !!! Pin
Marcos Meli12-Apr-06 11:40
Marcos Meli12-Apr-06 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.