Click here to Skip to main content
15,921,660 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reports... Ahhhh Pin
Michael P Butler27-Oct-04 2:46
Michael P Butler27-Oct-04 2:46 
GeneralMsn Messenger Programming Pin
Adnan Siddiqi26-Oct-04 7:20
Adnan Siddiqi26-Oct-04 7:20 
GeneralRe: Msn Messenger Programming Pin
Nick Parker26-Oct-04 7:39
protectorNick Parker26-Oct-04 7:39 
GeneralRe: Msn Messenger Programming Pin
Adnan Siddiqi26-Oct-04 8:46
Adnan Siddiqi26-Oct-04 8:46 
Generalmouse hover / mouse leave Pin
ee9903526-Oct-04 6:25
ee9903526-Oct-04 6:25 
GeneralRe: mouse hover / mouse leave Pin
Heath Stewart26-Oct-04 6:54
protectorHeath Stewart26-Oct-04 6:54 
GeneralRe: mouse hover / mouse leave Pin
ee9903526-Oct-04 7:10
ee9903526-Oct-04 7:10 
GeneralRe: mouse hover / mouse leave Pin
Heath Stewart26-Oct-04 10:19
protectorHeath Stewart26-Oct-04 10:19 
Sorry, I missed that the first time. It really helps if you post code correctly on this site. Use <PRE> tags (or the "pre" toolbar button below) for code blocks (that way you can tabify your code and use a fixed-width font) and <CODE> tags for inline code (like variables, methods, and even the tag names I mentioned, which are HTML-encoded).

As I mentioned before, the code inside MouseHover will continue to execute. The event will not fire anymore, but that doesn't stop the implementation from continuing. Unless you stop the code somehow it will continue.

The problem you're facing is because your handlers for both the MouseLeave and MouseHover events are running in the same thread. Your MouseLeave event handler won't execute until your MouseHover event handler completes.

There are many ways to solving this, but you really should read about threading applications if you're not familiar with it already. You can start by reading Threading[^] in the .NET Framework SDK on MSDN Online.

You execute your MouseHover event handler implement in a separate thread (move it into a new method). What you absolutely must do is use Control.Invoke to actually set the PictureBox.Image - you must make modifications - and most often, even read properties - from within the thread on which the control to be modified was created. If you don't, undefined problems may - and most often do - occur.

This way, since that code is executing in a separate thread your MouseLeave event handler is called at the proper time and your variable is set. When your MouseHover implementation loop reads that variable (that you don't need to invoke to get; only properties and methods that interop with the Win32 APIs for the control class, since every Windows Forms control encapsulates Win32 APIs and most encapsulate the Windows Common Controls) can stop and everything happens in the right order.

Another way is to start the MouseHover implementation in a separate thread, which you keep a reference to. In your MouseLeave event handler, call Abort on that thread reference, but make sure you handle any ThreadAbortExceptions that will be thrown.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: mouse hover / mouse leave Pin
ee9903527-Oct-04 7:45
ee9903527-Oct-04 7:45 
GeneralRe: mouse hover / mouse leave Pin
Heath Stewart27-Oct-04 14:08
protectorHeath Stewart27-Oct-04 14:08 
QuestionRAS API Wrapped in C#??? Pin
mrr26-Oct-04 5:57
mrr26-Oct-04 5:57 
AnswerRe: RAS API Wrapped in C#??? Pin
Heath Stewart26-Oct-04 7:03
protectorHeath Stewart26-Oct-04 7:03 
AnswerRe: RAS API Wrapped in C#??? Pin
Alex Korchemniy26-Oct-04 11:57
Alex Korchemniy26-Oct-04 11:57 
GeneralXmlElement.SetAttribute not working as expected Pin
Colin Angus Mackay26-Oct-04 5:10
Colin Angus Mackay26-Oct-04 5:10 
GeneralRe: XmlElement.SetAttribute not working as expected Pin
Heath Stewart26-Oct-04 7:00
protectorHeath Stewart26-Oct-04 7:00 
QuestionC++ header to .NET? Pin
hagay_ar26-Oct-04 4:44
hagay_ar26-Oct-04 4:44 
AnswerRe: C++ header to .NET? Pin
Heath Stewart26-Oct-04 6:23
protectorHeath Stewart26-Oct-04 6:23 
GeneralC# with some code in MFC Pin
ee9903526-Oct-04 4:40
ee9903526-Oct-04 4:40 
GeneralRe: C# with some code in MFC Pin
Judah Gabriel Himango26-Oct-04 5:20
sponsorJudah Gabriel Himango26-Oct-04 5:20 
GeneralRe: C# with some code in MFC Pin
Heath Stewart26-Oct-04 6:30
protectorHeath Stewart26-Oct-04 6:30 
GeneralSleep function in C# Pin
Ariadne26-Oct-04 4:16
Ariadne26-Oct-04 4:16 
GeneralRe: Sleep function in C# Pin
Judah Gabriel Himango26-Oct-04 4:24
sponsorJudah Gabriel Himango26-Oct-04 4:24 
GeneralRe: Sleep function in C# Pin
Gary Thom26-Oct-04 4:29
Gary Thom26-Oct-04 4:29 
GeneralSending Messages between Networked Computers. Pin
acidik26-Oct-04 3:29
acidik26-Oct-04 3:29 
GeneralPlus: Error message when adding a MessageQueue control... Pin
acidik26-Oct-04 4:18
acidik26-Oct-04 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.