请帮助您优雅地解决我的小项目中的几个问题。我正在用c#(WinForms)开发一个小程序,该程序使用图片框而不是按钮。我为它们添加了一个类似“动画”的小功能:当您将鼠标悬停在它们上面时,它们会减小大小,当鼠标移开时,它们会返回其原始状态。实际上,我在这里有两个问题:
代码如下:
private void IconReduce(PictureBox picturebox)
{
originalLocation = picturebox.Location;
originalSize = picturebox.Size;
picturebox.Location = new Point(picturebox.Location.X + 2, picturebox.Location.Y + 2);
picturebox.Size = new Size(picturebox.Size.Width - 4, picturebox.Size.Height - 4);
}
private void IconNormal(PictureBox picturebox)
{
picturebox.Location = new Point(originalLocation.X, originalLocation.Y);
picturebox.Size = new Size(originalSize.Width, originalSize.Height);
}
private void pb_MouseEnter(object sender, EventArgs e)
{
IconReduce(sender as PictureBox);
}
private void pb_MouseLeave(object sender, EventArgs e)
{
IconNormal(sender as PictureBox);
}