Iconits

本文介绍了一种使用图标而非按钮的应用中实现视觉特效的方法。该控件能够在鼠标悬停时放大图标,并通过调整透明度来实现模糊效果。文章还详细介绍了如何在Visual Studio工具箱中添加并使用该控件。

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:

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.

转载于:https://www.cnblogs.com/junzhongxu/archive/2008/08/12/1265634.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值