'MouseDown Event After Seconds
I'm working on a project that have a touchscreen monitor. I have 4 picturebox with two event(Mouse Down , Mouse click ).
in this case, when i click on the picturebox another picture will visible.(this is easy part for me) .
now i want to have a mouseDown event with this condition:
if mousedown for 5second , a message box appear that have Yes or no, yes for Picturebox.visible = false; & No for Picturebox.visible = false;.
i dont know how to do it.i tried to enable a timer for mouseDown and disable for mouse up. but not worked fine.
how to mouse down for 5second, and something happen?
sorry for this rookie question, im new in C# & having some hard time. :D
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
timer1.Enabled = true;
if(inTime)
{
DialogResult dialogResult = MessageBox.Show("Sure?", "Hide the photo?", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
picturebox1.visible = false;
}
else if (dialogResult == DialogResult.No)
{
picturebox1.visible = true;
}
}
}
Solution 1:[1]
I hope that is what you meant.
int TimeToWait = 5;
DateTime DateTimeToFireTheMsgBox;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
DateTimeToFireTheMsgBox = DateTime.Now.AddSeconds(TimeToWait);
//timer1.Interval = 100; // milisec
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (DateTime.Now >= DateTimeToFireTheMsgBox )
{
timer1.Stop();
DialogResult dialogResult = MessageBox.Show("Sure?", "Hide the photo?",
MessageBoxButtons.YesNo);
pictureBox1.Visible = dialogResult != DialogResult.Yes;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
timer1.Stop();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
