如何在该项目中放置所有面板 [英] how do dispose all panel in this project

查看:58
本文介绍了如何在该项目中放置所有面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

添加按钮正常工作,但重置按钮不起作用(始终保留一个面板)

add button is correctly work But reset button Not Work (Always Keep one Panel)

Public Class Form1

    Private Sub clear(ByVal i As Control)
        Dim frmControl As Control
        For Each frmControl In i.Controls
            If TypeOf frmControl Is Panel Then
                frmControl.Dispose()
            End If
        Next
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButton.Click
        Static wc As SByte = 1

        Dim P As New Panel
        P.Name = "Panel" & WC.ToString
        P.Size = New System.Drawing.Size(144, 51)
        FlowLayoutPanel1.Controls.Add(P)
        

        'Add TextBox
        Dim tb As New TextBox
        tb.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        tb.Name = "TextBox" & WC.ToString
        tb.Dock = DockStyle.Top
        tb.AutoSize = True
        P.Controls.Add(tb)
        tb.Focus()

        'Add Play Button 1
        Dim b1 As New Button
        b1.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        b1.Name = "ButtonPlay" & WC.ToString
        b1.Size = New System.Drawing.Size(75, 23)
        b1.Location = New System.Drawing.Point(70, 23)
        b1.Text = "پخش"
        Me.AddButton.UseVisualStyleBackColor = True
        P.Controls.Add(b1)

        'Add Delete Button 2
        Dim b2 As New Button
        b2.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        b2.Name = "ButtonDelete" & WC.ToString
        b2.Size = New System.Drawing.Size(40, 23)
        b2.Location = New System.Drawing.Point(30, 23)
        b2.Text = "حذف"
        Me.AddButton.UseVisualStyleBackColor = True
        P.Controls.Add(b2)

        'Add Insert Button 3
        Dim b3 As New Button
        b3.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        b3.Name = "ButtonInsert" & WC.ToString
        b3.Size = New System.Drawing.Size(30, 23)
        b3.Location = New System.Drawing.Point(0, 23)
        b3.Text = "+"
        Me.AddButton.UseVisualStyleBackColor = True
        P.Controls.Add(b3)
        wc += 1

        AddButton.SendToBack()
        Button2c.SendToBack()

    End Sub


    Private Sub Button2c_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2c.Click
        clear(FlowLayoutPanel1)
    End Sub
End Class

推荐答案

您不应该那样做-您还没有从流布局面板的Controls数组中删除控件,而只是将它们放置了.
You shouldn''t do it that way - you haven''t removed the controls from the Controls array of the flow layout panel, just Disposed them.
Private Sub clear(i As Control)
    While i.Controls.Count > 0
        Dim c As Control = i.Controls(0)
        If TypeOf c Is Panel Then
            i.Controls.Remove(c)
            c.Dispose()
        End If
    End While
End Sub


这篇关于如何在该项目中放置所有面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆