When I create a data center charging system, I will encounter the following problem: the label, text, commandbutton, and other controls cannot be added to the parent form.
That is because only controls with align or invisible (such as timer) can be directly placed on the primary form of MDI. Because MDI is the container of other child forms. If a button can be placed, the button will be covered when the subform is displayed. You can first place a control with the align attribute on the MDI. For example, picturebox, and then put the button on picturebox. In this way, the buttons can be indirectly placed on the MDI main form.
Align attribute: return or set a value to determine whether the object can be displayed in any size, position, or top, bottom, left, or right of the form, and the size is automatically changed to fit the width of the form. The default value of an object in the MDI form is at the top, and its width is equal
Set the scalewidth attribute value.
The picturebox and data controls are the only standard controls that can be placed on the MDI form. The internal area of the MDI form is defined as the space not covered by the control. When an MDI child form is maximized in an MDI parent form, it does not overwrite any controls.
However, If you stretch the picturebox to an hour as large as the maximum size of the MDI form, the child form cannot be displayed. So how can we solve this problem?
I used the API function ---- setparent
Declaration method:
Private declare functionsetparent lib "USER32" (byval hwndchild as long, byval hwndnewparentas long) as long
Function: This function changes the parent window of a subwindow.
Parameters:
Hwndchild: the sub-window handle. Hwndnewparent: The new parent window handle. If this parameter is null, the desktop window becomes the new parent window.
Return Value: If the function succeeds, the return value is the original parent window handle of the Child Window. If the function fails, the return value is null.
The specific code is:
Privatesub rechargemenu_click ()
Setparentfrmrecharge. hwnd, frmmain. hwnd
Frmrecharge. Show
End sub