我有一个按钮的图像。我用图像的平面按钮。默认情况下,当您在按钮上单击或按住鼠标时,标准按钮中的窗口按钮的背景图像会发生变化。但是我想在鼠标保持事件中更改背景图像。
我正在使用visual studio 2008。
private void btn_MouseDown(object sender, MouseEventArgs e)
{
//Replace with the appropriate control/image/color change:
btn.BackColor = Color.Black;
}
private void btn_MouseUp(object sender, MouseEventArgs e)
{
//As mentioned above
btn.BackColor = SystemColors.Control;
//Show the MsgBox here
MessageBox.Show("The background is fine!");
}
我是葡萄牙人,请原谅我,因为“我的英语”。
创建一个包含2个图像的ImagemList。
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
'out the button
End Sub
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
'In the button
Button1.BackgroundImage = ImageList2.Images(1)
End Sub
我想如果你使用winforms会很复杂 - 当你把它标记为winforms时,你可能会这样做。我认为在winforms中你必须定义自己的控件以实现这一目标,这将耗费你很多时间和精力。或者,您可以使用mousedown和mouseup事件,但如果您想要更改其他内容,则该方法不是非常灵活。
但是,如果你不需要使用winforms,但你也可以使用WPF,那么有几种可能性,因为WPF就是为此而设计的。您可以定义自己的样式和模板,以更改控件的可视外观。要更改鼠标保持事件的颜色,可以使用触发器。有关模板的详细信息,请参阅以下页面:click
希望有所帮助。