A NumericUpDown
has 2 handles/controls: the outer spinbox, and the inner edit textbox-like control.
I need to get the handle of the inner textbox control. NumericUpDown.Handle
gives the outer handle.
The closest I found on Google to that is this this forum conversation. The trick is to use the UDM_GETBUDDY = WM_USER+106 = 0x0400+106
message which returns the handle of the buddy window, in our case the text edit.
The output was something like this at first:
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = new IntPtr(User32.SendMessage(outer, (0x0400 + 106), 0, 0));
But then the OP said this wasn't working, so someone suggested to use GetWindow(outer, GW_CHILD)
. where GW_CHILD = 5
control.Capture = true;
IntPtr outer = User32.GetCapture();
IntPtr inner = User32.GetWindow(outer, 5);
For both of these methods, I always end up with inner = 0
, which is obviously not the right answer. However, OP stated method 2 seemed to work, so I might be doing something wrong.
By the way, the "capture" mechanic seems to be useless, as I can simply use:
IntPtr outer = control.Handle;
Which returns the same.
So, any ideas on how to get the inner textbox handle?
It is implemented very differently in Winforms, no buddy control. Getting a reference to the text box portion is easy to do, although it violates several encapsulation rules. Not really a problem, NumericUpDown is frozen in time and will never change.
var box = (TextBox)numericUpDown1.Controls[1];
Be careful with poking properties for that TextBox control, not all of its events are implemented.