我有一个问题需要帮助解决,希望您能提供帮助。
如果此问题已经被问过了,请谅解,我找不到类似的答案。
我的想法是当单击picturebox时将图像更改为ON。
如果按住picturebox超过2秒钟,则打开一个新窗体并将picturebox保持为OFF。
但是,如果单击picturebox ON,然后按住2秒钟,然后返回,则需要保持picturebox状态为ON。
这是我迄今为止尝试过的。
我相信为了使其正常工作,我需要停止MouseUp事件的发生。
是否有一种方法可以在Tick发生时停止MouseUp?
是否有更简单/更好的方法来做到这一点?
任何帮助都将不胜感激。
private void time_HoldDownInternal_Tick(object sender, EventArgs e)
{
time_HoldDownInternal.Enabled = false;
time_HoldDownInternal.Interval = 1000;
form1show.Visible = true;
}
private void pb_pictureBoxTest_MouseDown(object sender, MouseEventArgs e)
{
mainMenuVariables.mousedown = true;
time_HoldDownInternal.Enabled = true;
}
private void pb_pictureBoxTest_MouseUp(object sender, MouseEventArgs e)
{
mainMenuVariables.mousedown = false;
//MessageBox.Show("mouse up");
time_HoldDownInternal.Enabled = false;
time_HoldDownInternal.Interval = 1000;
}
private void pb_pictureBoxTest_Click(object sender, EventArgs e)
{
if (mainMenuVariables.mousedown == true)
{
if (mainMenuVariables.pictureBox == false)
{
mainMenuVariables.pictureBox = true;
pb_pictureBoxTest.Image = new Bitmap(mainMenuVariables.pictureBoxOn);
return;
}
if (mainMenuVariables.pictureBox == true)
{
mainMenuVariables.pictureBox = false;
pb_pictureBoxTest.Image = new Bitmap(mainMenuVariables.pictureBoxOff);
return;
}
}
if (mainMenuVariables.mousedown == false)
{
//nothing
}
}
if ( clickDuration > TimeSpan.FromSeconds(2)) { // 进行“保持”逻辑(例如打开对话框等) } else
- justin89if (clickDuration < TimeSpan(2))
并进行正常的“On”/“Off”图像交换即可。 - Tyson