devxlogo

Dynamically Positioning Controls at Runtime

Dynamically Positioning Controls at Runtime

Question:
It is easy to use control arrays to load controls inside a container. Now the problem is I do not know how many containers e.g., groups of option buttions, I will have until runtime. So the question seems to be how do you dynamically load a control, say an option button and tell it to belong to a dynamically loaded container, say a frame? Any ideas (other than ugly workaround like draw m (>=n) invisible container/controls at design time and make n of them visible at runtime)?

Answer:
The SetParent API call will let you reparent controls to other containers. All controls have a hWnd property, which uniquely identifies the control within Windows. The SetParent function takes two hWnd arguments: the parent’s hWnd, and the new child’s hWnd. You can look at the documentation in the Windows SDK help file, and here is the decalare statement:

Declare Function SetParent% Lib "user" (ByVal h%, ByVal h%)
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist