2

Here is a code from another post in StackOverFlow, which will change cursor in window caption:

 protected override void WndProc(ref Message m) {
        if (m.Msg == 0x20) {  // Trap WM_SETCUROR
            if ((m.LParam.ToInt32() & 0xffff) == 2) { // Trap HTCAPTION
                Cursor.Current = Cursors.Hand;
                m.Result = (IntPtr)1;  // Processed
                return;
            }
        }
        base.WndProc(ref m);
    }

Source: https://stackoverflow.com/a/6484627/4871566

But there are three additional problems I want to solve:

1- While moving the window (with holding down the left-mouse button) the cursor will change to its windows default again. Is there any way to change cursor to my chosen one while moving the form window?

2- When I load a child form as ShowDialog(), the main form will be disable and user can not interact with it.I can change The cursor in child form's area, but when the cursor is outside the child form's area (window), it will be the system windows default. Is there any way to change the cursor here outside?

3- Is there any way to change cursor of Message Boxes Caption Bar?

Amittai Shapira
  • 3,749
  • 1
  • 30
  • 54
Inside Man
  • 4,194
  • 12
  • 59
  • 119

2 Answers2

2

1) I made a little sample application for your problem, but I could not replicate your error. At the demo it stayed the same all the way through when I moved the window. It also restored itself when I left the caption area and returned.

So you might want to check that you are not reseting the cursor yourself somewhere.

A work-around I could think of is to intercept the Control.CursorChanged event and set your cursor there, effectively reseting any changes made through the windows base.

2) The problem is that the parent window is no longer enabled when you use the ShowDialog method. I tried using Show instead and it worked flawlessly.

Now this is tricky as you are loosing the modal attributes of the ShowDialog method. If you still absolutely have to do it, then you could reimplement a ShowDialog logic yourself that accomplishes the same thing without setting the Enabled property to false.

0

3- Is there any way to change cursor of Message Boxes Caption Bar?

In the .NET Framework, MessageBox uses native methods, so you cannot override the WndProc method. It even doesn't has one, since there is no Control element. In Mono, on the other hand, there is a MessageBoxForm, which you can try to do it, but I cannot guarantee it will work. Either way, if you're going to write your own dialog logic because of your second question, then you're halfway through writing your own message box form.

Logerfo
  • 469
  • 5
  • 17