System.Windows.Controls.TextBox Handle

2019-01-28 23:41发布

问题:

I feel like I'm missing something really obvious here.

I know that forms in general have a Handle property, but I am using a System.Windows.Controls.TextBox and it does not have a Handle property.

How do I access the TextBox's handle? I noticed that RichTextBox has the Handle property, so why not the regular TextBox?

回答1:

You can just call Handle on the TextBox. It is an inherited property from System.Windows.Forms.Control.

Edit: Question was updated to ask about WPF

WPF doesn't use handles like a typical Win32 application or WinForms application. Each control is not its own Window in WPF. You can verify this with Spy++, it cannot differentiate between each control. Therefore you cannot SendMessage to the individual controls like you can with WinForms and Win32 apps.

You can use WindowInteropHelper to get the parent window handle of a WPF window.