I have a C# WinForms application that has a panel
. The panel loads a UserControl
and the UserControl
contains a DataGridView
.
In my UserControl
, I have an event handler for the MouseDown
event on the DataGrid
private void palletsGrid_MouseDown(object sender, MouseEventArgs e)
{
try
{
EventHandler handler = onScrolling;
if (handler != null)
{
handler(this, new EventArgs());
}
}
Catch (Exception ex)
{
Logging.LogWarn("Mouse down error: ", ex);
}
}
Where onScrolling
is a publicly declared EventHandler
property.
I deal with this EventHandler
in the main form because, I have a timer that auto refreshes every 5 seconds. So I need the main form to know to stop refreshing when this event (scrolling through the DataGridView
) happens.
In my main form, this is what I am doing:
private void userControl_ScrollEvent(object sender, EventArgs e)
{
try
{
timer1.Stop();
Timer pauseTimer = new Timer();
pauseTimer.Interval = 60000;
pauseTimer.Start();
pauseTimer.Tick += new System.EventHandler(pauseTimer_Tick);
}
catch (Exception ex)
{
Logging.LogFatal("Scroll event capture error: ", ex);
}
}
What this does is, when the user is scrolling through the DataGridView
, the main form stops the auto refresh for 60 seconds. Once the 60 second pauseTimer
ticks, the refreshTimer
resumes like normal.
Problem:
I need my form to know when I touch the screen twice. As in, if I touch the screen now, the timer starts. Does not refresh for 60 seconds. If I touch it again, the 60 seconds needs to start from the second touch. Not the first. So every time I touch the screen, the pauseTimer
needs to restart.