Dynamically Positioning Controls at Runtime

Dynamically Positioning Controls at Runtime

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)?

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%)


Share the Post: