WinFrom鼠标经过时图片按钮放大缩小

public partial class Form2 : Form
{
    Size szStandard 
= new Size();

    
/// <summary>
    
/// 系统构造函数
    
/// </summary>
    public Form2()
    {
        InitializeComponent();

        
foreach (Control ctrl in this.Controls)
        {
            
if (ctrl is PictureBox)
            {
                ctrl.MouseHover 
+= new EventHandler(ctrl_MouseHover);
                ctrl.MouseLeave 
+= new EventHandler(ctrl_MouseLeave);
            }
        }
    }
    
/// <summary>
    
/// 鼠标移开图标缩小事件
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void ctrl_MouseLeave(object sender, EventArgs e)
    {
        PictureBox picbox 
= (PictureBox)sender; picbox.Size = szStandard;
    }
    
/// <summary>
    
/// 鼠标移上图标放大事件
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>
    void ctrl_MouseHover(object sender, EventArgs e)
    {
        
//每次放大图片原大小的20%
        PictureBox picbox = (PictureBox)sender; szStandard = picbox.Size; picbox.Size = Size.Ceiling(new SizeF(picbox.Width * 1.2f, picbox.Height * 1.2f));
    }
}

 

posted on 2010-09-23 11:39  一路前行  阅读(654)  评论(0编辑  收藏  举报