Click here to Skip to main content
6,292,426 members and growing! (10,960 online)
Email Password   helpLost your password?
Desktop Development » Button Controls » General     Intermediate

Iconits

By hanifku

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.
C#.NET 1.1, .NET 2.0, Win2K, WinXP, GDI+, VS.NET2003, VS2005, Dev
Posted:12 Apr 2006
Views:137,511
Bookmarked:167 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
67 votes for this article.
Popularity: 8.36 Rating: 4.58 out of 5
1 vote, 1.5%
1
2 votes, 3.0%
2
5 votes, 7.5%
3
8 votes, 11.9%
4
51 votes, 76.1%
5

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 name Type Description
    Blur Boolean Set to true if you want the transparency effect, set to false otherwise.
    Icon Bitmap Set the icon from any available image.
    IconSize Size Icon initial size.
    Size Size Icon actual size when mouse hovers over it.
    TooltipText String Icon'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:

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

About the Author

hanifku


Member
Yojana Hanif was love to code, he is just graduated from Institut Teknologi Sepuluh Nopember Surabaya Indonesia.
Occupation: Web Developer
Location: Indonesia Indonesia

Other popular Button Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 47 (Total in Forum: 47) (Refresh)FirstPrevNext
Generalvery good job [modified] PinmemberiowhfojfljLEJFSFLJafa0:45 12 Sep '07  
GeneralFurther simplification Pinmemberblackholeat18:50 17 Jan '07  
GeneralRe: Further simplification Pinmembersly59616:18 23 Apr '07  
GeneralWhat kind of icon does one want to import Pinmembergordingin5:02 19 Nov '06  
GeneralResource Question Pinmembergordingin4:52 19 Nov '06  
Generalso cool Pinmemberamin keshani2:05 12 Oct '06  
General[LONG] Big update with everybody contributions PinmemberLelhu8:05 18 Sep '06  
GeneralRe: [LONG] Big update with everybody contributions Pinmemberfemme11:42 8 Mar '07  
QuestionMemory Problem fixed? PinmemberK3211:31 18 Aug '06  
QuestionRe: Memory Problem fixed? Pinmemberswtechno5:23 18 Aug '06  
GeneralExcellent!! But maybe an addition.... PinmemberK32121:30 17 Aug '06  
GeneralBug + Fix: Iconit after visibility change PinmemberKel_23:37 24 Jul '06  
GeneralBug + Fix: BackColor problem PinmemberPink Floyd13:07 10 May '06  
GeneralA question PinmemberMengChih0:20 25 Apr '06  
AnswerRe: A question PinmemberPink Floyd13:08 10 May '06  
GeneralRe: A question PinmemberMengChih0:08 15 May '06  
Generalvery creative work ! PinmemberBillWoodruff16:25 24 Apr '06  
Generaltooltip behavior Pinmemberagarcian8:25 21 Apr '06  
GeneralRe: tooltip behavior Pinmemberjayoscar21:48 23 Apr '06  
GeneralRe: tooltip behavior PinmemberPink Floyd5:04 11 May '06  
GeneralA more efficient alpha routeen... PinmemberJon Rista18:21 20 Apr '06  
GeneralRe: A more efficient alpha routeen... PinmemberJon Rista18:38 20 Apr '06  
GeneralRe: A more efficient alpha routeen... Pinmemberjayoscar1:30 21 Apr '06  
GeneralRe: A more efficient alpha routeen... PinmemberJon Rista13:06 22 Apr '06  
GeneralRe: A more efficient alpha routeen... Pinmembermrsnipey17:56 8 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Apr 2006
Editor: Smitha Vijayan
Copyright 2006 by hanifku
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project