【发布时间】:2018-02-03 22:29:34
【问题描述】:
我正在创建一个测试 C# WinForm 应用程序,并且我有一个关闭按钮。当您将鼠标悬停在按钮上时,BackColor 会变为较浅的颜色。当您停止将鼠标悬停在它上面时,按钮会变回背景颜色。单击按钮时,它会变为白色,松开时,会变回背景色。我的问题是,如果有人将鼠标悬停在上面并更改为悬停颜色,然后有人单击并再次更改颜色,如果他们将鼠标从按钮上拖开,我可以将其更改回悬停颜色吗?
代码:
public Form1()
{
InitializeComponent();
bunifuImageButton1.MouseEnter += bunifuImageButton1_MouseHover;
bunifuImageButton1.MouseLeave += bunifuImageButton1_MouseLeave;
bunifuImageButton1.MouseDown += bunifuImageButton1_MouseDown;
bunifuImageButton1.MouseUp += bunifuImageButton1_MouseUp;
}
private void bunifuImageButton1_MouseHover(object sender, EventArgs e)
{
bunifuImageButton1.BackColor = SystemColors.Highlight;
}
private void bunifuImageButton1_MouseLeave(object sender, EventArgs e)
{
bunifuImageButton1.BackColor = SystemColors.HotTrack;
}
private void bunifuImageButton1_MouseDown(object sender, EventArgs e)
{
bunifuImageButton1.BackColor = SystemColors.Control;
}
private void bunifuImageButton1_MouseUp(object sender, EventArgs e)
{
bunifuImageButton1.BackColor = SystemColors.HotTrack;
}
private void bunifuImageButton1_Click(object sender, EventArgs e)
{
this.Close();
}
【问题讨论】: