我的课程基本上是一个表单的不同控件的集合,我希望它能删除自己'。课程中的一个按钮是“删除”按钮。应删除该类实例的按钮(或至少使其不再可访问)。有没有更好的方法来做到这一点,而不仅仅是通过并将类中的每个变量设置为“没有”'?这是New()子和类变量。
Class paperView
Dim paper As examPaper
Dim WithEvents done As CheckBox
Dim subject As Label
Dim mYear As Label
Dim location As TextBox
Dim mLocation As TextBox
Dim WithEvents find As Button
Dim WithEvents mFind As Button
Dim WithEvents open As Button
Dim WithEvents mOpen As Button
Dim WithEvents del As Button
Dim startPt As Point
Public Sub New(ByVal x As Integer, ByVal y As Integer, ByRef parent As Control, ByVal base As examPaper)
paper = base
done = New CheckBox()
done.Parent = parent
done.Location = New Point(x, y)
done.Size = New Size(20, 20)
done.Text = ""
done.Checked = paper.fin
subject = New Label()
subject.Parent = parent
subject.Location = New Point(20 + done.Width, y - 2)
subject.Text = paper.subject
subject.MinimumSize = New Size(50, 0)
subject.TextAlign = ContentAlignment.MiddleCenter
location = New TextBox
location.Parent = parent
location.Location = New Point(subject.Left + subject.Width, y)
location.ReadOnly = True
location.Width = 200
location.Text = paper.location
location.TextAlign = HorizontalAlignment.Center
mLocation = New TextBox
mLocation.Parent = parent
mLocation.Location = New Point(10 + location.Left + location.Width, y)
mLocation.ReadOnly = True
mLocation.Width = 200
mLocation.Text = paper.mLocation
mLocation.TextAlign = HorizontalAlignment.Center
mYear = New Label()
mYear.Parent = parent
mYear.Location = New Point(mLocation.Width + mLocation.Left, y - 2)
mYear.Text = paper.mYear
mYear.MinimumSize = New Size(50, 0)
mYear.TextAlign = ContentAlignment.MiddleCenter
find = New Button()
find.Parent = parent
find.Location = New Point(mYear.Width + mYear.Left, y)
find.Text = "Find Paper"
find.Width = 70
mFind = New Button()
mFind.Parent = parent
mFind.Location = New Point(find.Width + find.Left, y)
mFind.Text = "Find MS"
mFind.Width = 70
open = New Button()
open.Parent = parent
open.Location = New Point(mFind.Width + mFind.Left, y)
open.Text = "Open Paper"
open.Width = 80
mOpen = New Button()
mOpen.Parent = parent
mOpen.Location = New Point(open.Width + open.Left, y)
mOpen.Text = "Open MS"
mOpen.Width = 80
del = New Button()
del.Parent = parent
del.Location = New Point(mOpen.Width + mOpen.Left, y)
del.Text = "Delete"
del.Width = 70
End Sub
Private Sub del_Click(sender As Object, e As EventArgs) Handles del.Click
'delete code
End Sub
End Class
删除按钮就是那个名为' del'的按钮。使用基本的点击事件处理程序。
感谢。