02-09-16, 06:24 PM
PHP كود :
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CreateButton("Close", New Point(20, 20), New Size(75, 24))
End Sub
Private Sub CreateButton(buttonname As String, buttonLocation As Point, buttonSize As Size)
Dim b As New Button
With b
.Name = buttonname
.Location = buttonLocation
.Size = buttonSize
.Text = buttonname
End With
AddHandler b.Click, AddressOf Button_Click
Me.Controls.Add(b)
End Sub
Private Sub Button_Click(sender As Object, e As EventArgs)
Me.Close()
End Sub
End Class
عليك ان تستخدم AddHandler كما في الكود اعلاه
أيضا و يفترض لاحقا ان تستخدم RemoveHandler لتتخلص من الباتون من خلال Dispose الخاصة ب الفورم

