For the charging system of the data center that has just been claimed.
In this system, the outermost layer is an MDI form. Other operations are performed in the MDI subform.
When we see this form, we do not hesitate to say that the main form of this form is an MDI form. All others are their subforms.
Therefore, when creating a system, create an MDI form. However, we will find that buttons and other controls cannot be added to the MDI form. Therefore, we need a container control. Most people will think of picturebox because it is a very simple and representative container control.
There was nothing wrong with the main form. However, when you have an MDI subform form1, you will find the problem. No matter how you adjust it, The subform form1 cannot be seen.
The following is a small example to solve the above problems.
This is an MDI form. The above is a picturebox control. When you click the button, the form1 subform is displayed.
When you click the button, you will see the following situation.
The child forms form1 and picture are at the same level. Therefore, the child form is invisible.
Here is a solution:
Use the API function ---- to set form1 to a subform of picturebox. In this way, form1 can be displayed in front of picturebox.
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub Command1_Click() SetParent Form1.hWnd, MDIForm1.hWnd Form1.ShowEnd Sub
By using the API function, you can place the subform form1 on picturebox and display it.
However, if form1 is not completely displayed, you need to set the length and width of the child form.
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub Command1_Click() SetParent Form1.hWnd, MDIForm1.hWnd Form1.Show Form1.Width = Picture1.ScaleWidth Form1.Height = Picture1.ScaleHeightEnd Sub
Although the problem is solved, the appearance of the view is broken.
The title bar after the MDI sub-form is maximized is under the menu bar of the MDI form. In addition, after the MDI subform is minimized, it cannot be found.
For a more user-friendly main interface, we will explain it in the next section.