471,311 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

System.Timers.Timer question ???

Hi,
I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has
been hovered on for 2 seconds. I was thinking of using DataGrid.Hover, but
then decided to try this instead:

static System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
private void dg_MouseMove(object sender, System.Windows.Forms.MouseEventArgs
e)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 2000;
timer.Start();
DataGrid.HitTestInfo hitInfo = dg.HitTest(e.X, e.Y);
eX = hitInfo.Column; eY = hitInfo.Row;
timer.Elapsed+=new System.Timers.ElapsedEventHandler(OnTimedEvent);
timer.AutoReset = false;
timer.Enabled = true;
}
private static void OnTimedEvent(object source,
System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("2 secs");
....add tooltip stuff here...
}

When I run it, it does wait 2 seconds before the messagebox comes up, but
then a new messagebox pops up every 1/2 second or so (even if I don't move
the mouse again). I was under the impression that timer.Autoselect would
prevent that from happening. I think I have other questions too, but I'd
like to get this step working before I do anything else.

Thanks!!!!
Mel
Dec 12 '05 #1
1 1964
Have you any idea how many "mousemove" events are fired when you move your
mouse over an interface object? Quite a few. It just depends on how long you
move your mouse over the object. If you only want to handle the event once,
you need to use some sort of boolean variable that is checked before
execting the MessageBox code. The handler would check the value, see if it
is false, and if not, set it to false, and execute code. If you want it to
fire more than once, you also need to have a way of turning it back on. How
you do this is up to you.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:59**********************************@microsof t.com...
Hi,
I'm have a datagrid, and I'm trying to have a tooltip pop up if a cell has
been hovered on for 2 seconds. I was thinking of using DataGrid.Hover,
but
then decided to try this instead:

static System.Windows.Forms.Timer timer = new
System.Windows.Forms.Timer();
private void dg_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs
e)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 2000;
timer.Start();
DataGrid.HitTestInfo hitInfo = dg.HitTest(e.X, e.Y);
eX = hitInfo.Column; eY = hitInfo.Row;
timer.Elapsed+=new System.Timers.ElapsedEventHandler(OnTimedEvent);
timer.AutoReset = false;
timer.Enabled = true;
}
private static void OnTimedEvent(object source,
System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("2 secs");
...add tooltip stuff here...
}

When I run it, it does wait 2 seconds before the messagebox comes up, but
then a new messagebox pops up every 1/2 second or so (even if I don't move
the mouse again). I was under the impression that timer.Autoselect would
prevent that from happening. I think I have other questions too, but I'd
like to get this step working before I do anything else.

Thanks!!!!
Mel

Dec 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Peter Johnsson | last post: by
9 posts views Thread by Mark Rae | last post: by
5 posts views Thread by Michael C# | last post: by
2 posts views Thread by cntams | last post: by
4 posts views Thread by Liverpool fan | last post: by
2 posts views Thread by BobAtVandy | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.