C#。我有18个按钮可供选择,但是在选择之前。当鼠标指向Button时,如何使用BackgroundImage放大Button?就像工具提示,当您将光标指向时,它将显示文本。但就我而言,它将扩大Button。谢谢

Button[] ButtonSelect = new Button[17];
for (i = 1; i <= 18; i++)
{
ButtonSelect[i] = new Button();
ButtonSelect[i].BackgroundImage = Properties.Resources.SelectImages[i];
}

最佳答案

MouseEnter事件中使Button的尺寸变大:

Button btn = (Button)sender;
int width = btn.Size.Width;
int height = btn.Size.Height;
int larger = 10;
btn.Size = new Size(width + larger, height + larger);


然后在MouseLeave事件中,通过缩小按钮大小来做相反的事情。

您可以像这样连接事件:

for (i = 1; i <= 18; i++)
{
ButtonSelect[i] = new Button();
ButtonSelect[i].BackgroundImage = Properties.Resources.SelectImages[i];
ButtonSelect[i].MouseEnter += new System.EventHandler(Btn_MouseEnter);
ButtonSelect[i].MouseLeave += new System.EventHandler(Btn_MouseLeave);
}

09-26 18:11