1

Ok, as I understand things (and I'm probably wrong here), a Windows Form has a Cursor property and so do all child controls. This cursor is surprisingly defaulting to Cursors.Default, which is the arrow pointer. So far, so good.

Now, if I want a different cursor on areas of the form not covered by controls, I can check the form mouse move event and change the cursor therein. So now what I expect is that when the cursor is moved over the form, the cursor changes to whatever I set it to in Form.MouseMove_Handler, but when the cursor is moved over a child control of the form, it changes to the child's Control.Cursor.

However this is not what I see. I see my cursor changing when moving over the form, but when it moves over a child control, it remains as it was when moving over the parent form. The Control.Cursor property doesn't seem to be honoured at all.

Do I have to handle MouseMove, MouseEnter and MouseLeave events for ALL controls on my form in order to get this to work?

4
  • Your Form's MouseMove_Handler is also running when the mouse is over a control, thus changing the cursor back from whatever the control thought it should be. Commented Jun 14, 2012 at 9:38
  • I don't think you need to handle the Mouse movements. Why don't you set the Form.Cursor to the cursor you need and the controls cursor to Cursor.Default ? Commented Jun 14, 2012 at 9:39
  • Steve, I've got a borderless form and I'm implementing drag/size operations, so I'm changing the cursor on the form borders for size and changing the cursor elsewhere on the form for move/drag. Klaus tells me something I didn't realise: the form's MouseMove is called when the mouse is over a control? That seems a bit daft to me :) Commented Jun 14, 2012 at 9:41
  • I see, but I still think that if you explicitly set the cursor to move/drag on every controls you override the actual setting on the form. Can't be sure, but I will give a try. Commented Jun 14, 2012 at 9:43

1 Answer 1

2

From MSDN

Assign a Cursor to the Cursor property of the control to change the cursor displayed when the mouse pointer is over the control. To temporarily change the mouse cursor for all controls on your application set the Cursor.Current property. Typically you would set the Cursor.Current property to a wait cursor when populating a ComboBox or saving or loading a file.

The Cursor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default. For more information about ambient properties, see the AmbientProperties class or the Control class overview.

Notes to Inheritors

When overriding the Cursor property in a derived class, use the base class's Cursor property to extend the base implementation. Otherwise, you must provide all the implementation. You are not required to override both the get and set methods of the Cursor property; you can override only one if needed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I didn't know about `ambient' properties. I will give it a shot. Having said that, it still makes zero sense given that the parent form MouseMove event still seems to be called even when the mouse is over a child control. I guess I have to check that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.