Search code examples
c#compact-frameworkwindows-ce

C# Form2.ShowDialog() and Mouse Cursor


(NET Compact Framework 3.5, Windows CE 6.0)

I want to hide mouse cursor.
So, I use Curosr.Hide()

I have two forms, Form1, Form2.
The size of Form2 is smaller than Form1.
PictureBox1 is in Form1.
When PictureBox1 is clicked, Form2 will be opened. (modal)

At this point, the mouse cursor suddenly appears outside area of Form2.
MouseDonw PictureBox1 -> Form2.ShowDialog -> Show MouseCursor

I have never done Cursor.Show()

Why does the mouse cursor appear?


Added the following
I moved Form2.ShowDialog() from 'MouseDown Event' to 'MouseUp Event'. then it is resolved. Why?


Solution

  • First, form show and other 'actions' usually are done with a mouse click event. That is fired after mouse down and mouse up.

    If you break the normal sequence, ie show a form on a mouse down event, the GUI is in 'Mouse down/move' mode, for example to drag an element or draw a line.

    As each element can show/hide the mouse cursor, the Windowing System recognizes youre Cursor Hide on the second form, but the first form still shows the mouse cursor as the Mouse Up event is not done.

    If you would like to know more about the Basics, you should look at a native WndProc and how are Window Messages are handled. Programming Windows by Charles Petzold is still the bible for Windows programming.