C # FAQs about window handle

Source: Internet
Author: User

1. How to obtain a window handle?
For example, you can obtain the handle of the window picturebox control (which can be used by other controls,
Intptr handle = picturebox. Handle;

2. Note: The process of creating a window is totally different from that of creating a window !!!

When a window is created, there is no handle in the window, only application. run (form) or Form. A handle is available only after show (). That is, a handle is available only after the window is displayed or the message loop is started! If form = new form () is created after form is created, the form is called in the main thread. handle. If the handle has not been created, referencing this attribute will force the creation of the handle, which will have a fatal impact on the system logic.

3. How can I determine whether a window handle has been created?

Use the ishandlecreated attribute: This attribute indicates whether the control has a handle associated with it. If a handle has been assigned to the control, the value is true; otherwise, the value is false.

4. Some attributes:
(1) createcontrol: Creates controls forcibly, including handles and any child controls.
(2) createhandle: Create a handle for the control,

Generally, you should not directly call the createhandle method. The preferred method is to call the createcontrol method, which forces the creation of a handle for the control and its child controls when creating the control. When you override createhandle in a derived class, make sure that the createhandle method of the base class is called to ensure that the handle has been created.
(3) destroyhandle: destroys the handle associated with the control.
(4) fromchildhandle: Retrieves controls containing the specified handle.
(5) fromhandle: return the current control associated with the specified handle
(6) handle: gets the window handle bound to the control. The value of the handle attribute is Windows hwnd. If the handle has not been created, referencing this property will force the creation of the handle.
(7) ishandlecreated: indicates whether the control has an associated handle. If the control has been assigned a handle, the value is true; otherwise, the value is false.
(8), recreatehandle: force a new handle for the control
(9), recreatinghandle: indicates whether the current handle is hitting

5. Note:
The handle is a random volume. Generally, two different results are returned when two operations are performed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.