我有一个PictureBox我用它作为按钮!
我有一个代码,当鼠标点击事件时图片更改! 但MouseMove也有不同的图像,即使我点击MouseMove事件执行并将图像更改回未被点击!
我的问题是如何阻止MouseMove事件并点击图片以便图片不会被更改?
这是我的代码
void Button_Mouse_Enter(object sender, MouseEventArgs e)
{
PictureBox _Button = (PictureBox)sender;
if (e.Button.Equals(MouseButtons.None))
{
_Button.ImageLocation = @"PATH\Button_Hover.jpg";
}
}
void Button_Mouse_Click(object sender, MouseEventArgs e)
{
PictureBox _Button = (PictureBox)sender;
if (e.Button.Equals(MouseButtons.Left))
{
_Button.MouseEnter -= Button_Mouse_Enter;
_Button.ImageLocation = @"PATH\Button_Click.jpg";
}
}
事件的创建方式如下:
Button_Plan.MouseEnter += (sender,e) => Button_Mouse_Enter(sender,e);
Button_Plan.MouseClick += (sender, e) => Button_Mouse_Click(sender, e);
我收到此错误:
Error 2 Argument 2: cannot convert from 'System.EventArgs' to 'System.Windows.Forms.MouseEventArgs'
如何将事件e参数作为MouseEventArgs传递?
答案 0 :(得分:1)
嗨试试看看它有多少效果 使用鼠标移动事件
void Button_Mouse_Move(object sender, EventArgs e)
{
if (e.Button.Equals(MouseButtons.None))
{
_BPictureBox _Button = (PictureBox)sender;
_Button.ImageLocation = @"PATH\Button_Hover.jpg";
}
}
void Button_Mouse_Click(object sender, EventArgs e)
{
if (e.Button.Equals(MouseButtons.Left))
{
_Button.MouseEnter -= Button_Mouse_Enter;
PictureBox _Button = (PictureBox)sender;
_Button.ImageLocation = @"PATH\Button_Click.jpg";
}
}
希望这会对你有所帮助