Cursors & MDI Apps

A

a

Hello,

I am doing some multithreading in an MDI app, and I can't seem to get the
cursor to stay as an Hourglass. I call:

Cursor.Current = cursors.wait

at the beginning of my routing, and set it back to cursors.default when the
thread ends (using a callback)

Any ideas here? Does Cursor.Current work, if called in the MDIParent, on
MDIChildren forms?

Thanks!

Kevin
 
P

Peter Huang

Hi Kevin,

This may be caused by that another thread accessed the control on the
winform.
You may take a look at the Control.Invoke method.
Control.Invoke Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWindowsFormsControlClassInvokeTopic.asp

Here are some articles about Multithreading in Windows Forms.
Safe, Simple Multithreading in Windows Forms, Part 1
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms06112002.asp

Safe, Simple Multithreading in Windows Forms, Part 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms08162002.asp

Safe, Simple Multithreading in Windows Forms, Part 3
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/htm
l/winforms01232003.asp

Give Your .NET-based Application a Fast and Responsive UI with Multiple
Threads
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

a

I don't think it was (is) a thread issue. I changed from Cursor.Current =
Cursors.WaitCursor to Cursor = Cursors.WaitCursor and half of my issue is
fixed. The other part is that when I 'mouseover' a listview in Details
view, i get the default, but anywhere else seems to show the WaitCursor.

Any ideas on this? Do I need to rig a handler to the listview? Seems odd.

Kevin
 
P

Peter Huang

Hi Kevin,

I am sorry for misunderstanding your meaning.
I think the Cursor.Current is used to set the current cursor only when the
message loop is stopped.
e.g. In the senario below, the message loop will stop because it is busy
running Button1_Click function, so after we set the Cursor.Current =
Cursors.WaitCursor it will keep the Cursors.WaitCursor.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Cursor.Current = Cursors.WaitCursor
For i As Long = 0 To 1000000000000
Dim j As Long = i
Next
Cursor.Current = Cursors.Default
End Sub

While the Cursor you refer to in your second statement means the Cursor
property of a control, it may be a window form or another control.
e.g.
If we set the Cursor property of winform as below, if we move the cursor
over windows forms area, the cursor will became Cursors.WaitCursor, while
it will become Cursors.Default if we move the cursor on a control whose
Cursor property is Cursors.Default even if it is on the windows form.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
End Sub

As for the problem that when we set the listview's Cursor property to
Cursors.WaitCursor, the cursor will not change when mouse moves over the
listview, that is a known issue.
So far as a workaround, we need to derived ourselves' listview and override
the wndproc to set the cursor.
Here is the sample code.
Imports System.Runtime.InteropServices

Public Class MyListView
Inherits ListView
Const WM_SETCURSOR = &H20
Public Declare Function SetCursor Lib "user32" Alias "SetCursor" (ByVal
hCursor As IntPtr) As IntPtr
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
if m.Msg = WM_SETCURSOR
SetCursor(Me.Cursor.Handle)
Return
End If
MyBase.WndProc(m)
End Sub
End Class

You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

a

JOKE: WHat do you call a known-issue when it's not known to you?
ANSWER: A Pain in the @$$

Thanks for the help.

Not susre I follow the Cursor.Current deal, I'll have to look into it later.

I will try to implement your listview fix later.

Thanks!

Kevin
 
P

Peter Huang

Hi Kevin,

I am sorry for misunderstanding the problem at the first time, I did not
relate the problem with the listview at the first reply, so I did not give
the information as the second reply do.

From your second reply, I redo the research and find the problem.

Anyway, I look forward to your reply after you have tried my suggestion, if
you still have any concern please feel free to let me know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top