By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Cursors & MDI Apps

P: n/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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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/de...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/de...us/dnforms/htm
l/winforms06112002.asp

Safe, Simple Multithreading in Windows Forms, Part 2
http://msdn.microsoft.com/library/de...us/dnforms/htm
l/winforms08162002.asp

Safe, Simple Multithreading in Windows Forms, Part 3
http://msdn.microsoft.com/library/de...us/dnforms/htm
l/winforms01232003.asp

Give Your .NET-based Application a Fast and Responsive UI with Multiple
Threads
http://msdn.microsoft.com/msdnmag/is...g/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.

Nov 20 '05 #2

P: n/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

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:MO**************@cpmsftngxa06.phx.gbl...
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/de...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/de...us/dnforms/htm l/winforms06112002.asp

Safe, Simple Multithreading in Windows Forms, Part 2
http://msdn.microsoft.com/library/de...us/dnforms/htm l/winforms08162002.asp

Safe, Simple Multithreading in Windows Forms, Part 3
http://msdn.microsoft.com/library/de...us/dnforms/htm l/winforms01232003.asp

Give Your .NET-based Application a Fast and Responsive UI with Multiple
Threads
http://msdn.microsoft.com/msdnmag/is...g/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.

Nov 20 '05 #3

P: n/a
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.

Nov 20 '05 #4

P: n/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


""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:cH**************@cpmsftngxa06.phx.gbl...
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.

Nov 20 '05 #5

P: n/a
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.

Nov 20 '05 #6

P: n/a
a
That does it!

Thanks
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:kg**************@cpmsftngxa06.phx.gbl...
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.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.