Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete a control by VB.NET

Shulou Source: shulou.com Published: 2022-06-02 09:02:02 10月03日 Update

This article is about how VB.NET deletes controls. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

When a control is a child of another control, for example, there are three child pictruebox in pictruebox, and the names of the child controls are stored in known variables, when we want to delete any of these controls, we can use the following methods:

Take a look at a piece of code first:

Control the state of the control

Private Sub mHDR_Control_Status

(ByVal p_Enabled As Boolean)

Dim iControls As Integer

Dim i As Integer

IControls = Me.gbxVoyage_HDR.

Controls.Count

For I = 0 To iControls-1

If TypeOf (Me.gbxVoyage_HDR.

Controls (I)) Is TextBox Or _

TypeOf (Me.gbxVoyage_HDR.Controls (I))

Is Infragistics.Win.Misc.UltraButton Then

Me.gbxVoyage_HDR.Controls (I).

Enabled = p_Enabled

End If

Next

DtpLoad_ETD.Enabled = p_Enabled

If gLoad_Type = "0" Then

BtnSave.Enabled = p_Enabled

BtnEdit.Enabled = Not p_Enabled

Else

BtnSave.Enabled = False

BtnEdit.Enabled = False

End If

TxtVoyageNO.Enabled = False

End Sub

To put it simply, use Me.gbxVoyage_HDR.Controls (I)), and if there are controls in the control, add Controls (I) to control Me.gbxVoyage_HDR.Controls (I) .controls (I).

Going back to the previous assumption, there are three more sub-pictruebox in pictruebox, and the main code to delete any one of them is as follows:

Public pics (1000) As System.

Windows.Forms.PictureBox

Dim pic1 as new New PictureBox

Dim pic2 as new New PictureBox

Dim pic3 as new New PictureBox

Dim j as integer=0

Dim Mainpic as new New PictureBox

Mainpic .Controls.add (pic1)

Pics (j) = pic1

Jackpot 1

Mainpic .Controls.add (pic2)

Pics (j) = pic2

Jackpot 1

Mainpic .Controls.add (pic3)

Pics (j) = pic3

Jackpot 1

An array of controls is used. When VB.NET deletes controls, delete them all: Mainpic .Controls.Clear ()

When VB.NET deletes the j control in the control: Mainpic .Controls.Remove (pics (j))

Thank you for reading! This is the end of this article on "how to delete controls in VB.NET". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Control time size code content more article control good practical variable name that is array article method state see knowledge reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Shulou Tech Info Xiaomi Docker