VB. NET sets the display level of controls and forms. vb.net controls

Source: Internet
Author: User

VB. NET sets the display level of controls and forms. vb.net controls

Preface: When VB. NET is used to develop the RF Detection System ADS, when an existing target MDI subform is activated, it is overwritten by other subforms, so that the target MDI subform cannot be displayed.

How can this problem be solved? I saw a post on the Internet that sets the display level of controls and forms in VB. NET, which is quite good. It is now reprinted for future use.

Solution:

1) Use the Controls attribute to display the child form as a child control to the front of all child Controls such as Panel.

Some controls can be used as controls for containers, such as Panel and PictureBox. When other controls are added to container controls, these child controls are combined into a set of controls, in this control set, each control has its own display order. The following uses Panel as an example (the methods for other container controls are the same ).

You can use the Controls attribute to display the child form as a sub-control of the Panel. The specific implementation code is as follows:

Private Sub frmQryBalance_Load(sender As Object, e As EventArgs) Handles MyBase.Load        Me.TopLevel = False        frmMain.Panel1.Controls.Add(Me)        frmMain.Panel1.Controls.SetChildIndex(Me, 0)        frmMain.Show()End Sub

The Add method above shows the frmQryBalance form as a sub-control to the Panel. The SetChildIndex method sets the display sequence of the sub-forms, and 0 shows the form to the front of all sub-controls.

2) use the Parent property to display the child form as a child control to the front of all child controls such as Panel.

The Code is as follows:

Private Sub frmQryBalance_Load(sender As Object, e As EventArgs) Handles MyBase.Load     Me.MdiParent = frmMain     Me.Parent = frmMain.Panel1     Me.BringToFront()     Me.Show()End Sub

BringToFront is to move the control to the front of the Z sequence. BringToFront does not make a control a top-level control.

The SendToBack method is the opposite of the BringToFront method. Move the control to the end of the Z sequence. If the control is a top-level control, this method cannot run correctly unless the control is active. A top-level control is a Form-like control. It is not a child control of another control. An active control is a visible control with an input focus. To use the SendToBack method for an inactive top-level control, you must first call the BringToFront method for the control.

3) Call the API method SetParent

In Visual Basic. Net, the "platform call" service is used to declare that Windows API functions have two specific implementation methods: ① use the DllImport feature class to declare Windows API functions. ② Use the "Declare" statement to Declare Windows API functions. Although the two methods have the same effect, there are great differences in complexity. The first method declaration process is complicated and it is easy to make mistakes when declaring Windows API functions, therefore, it is not advocated. The second method is relatively simple and retains many syntaxes in Visual Basic. Therefore, most of them use this method to declare Windows API functions.

The specific implementation method is as follows:

Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub frmQryBalance_Load(sender As Object, e As EventArgs) Handles MyBase.Load    setparent  me frmMain.Panel1End Sub

Reference: http://blog.csdn.net/zhang_xinxiu/article/details/8888510

Related Article

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.