05-02-20, 08:44 PM
(05-02-20, 03:40 PM)Sorax كتب : شكرا بس بعد التعديل بعد ميشتغل الهاندلس
كود :
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim pt As Point = New Point(10, 10)
For i As Integer = 0 To 3
Dim Btnx As Button = New Button
With Btnx
Btnx.Location = New System.Drawing.Point(5, 85)
Btnx.Text = "Send"
Btnx.Name = "Btnx" & (i + 1).ToString
Btnx.BackColor = System.Drawing.Color.White
Btnx.Size = New System.Drawing.Size(100, 25)
End With
Dim Panx As Panel = New Panel
With Panx
Panx.Location = pt
Panx.BackColor = System.Drawing.Color.Silver
Panx.Size = New System.Drawing.Size(111, 111)
End With
Dim Picx As PictureBox = New PictureBox
With Picx
Picx.Location = New System.Drawing.Point(30, 5)
Picx.Size = New System.Drawing.Size(50, 50)
Picx.BackColor = System.Drawing.Color.White
End With
Dim Labx As Label = New Label
With Picx
Labx.Location = New System.Drawing.Point(0, 63)
Labx.Size = New System.Drawing.Size(111, 15)
Labx.Text = "{NAME}"
Labx.TextAlign = System.Drawing.ContentAlignment.TopCenter
End With
' هنا يتم ضبط مكان كل باتون
pt.X += Panx.Height + 95
Panx.Controls.Add(Btnx)
Panx.Controls.Add(Picx)
Panx.Controls.Add(Labx)
FlowLayoutPanel1.Controls.Add(Panx)
Next
' هنا نضيف الحدث لكل باتون
For Each b As Button In Me.Controls.OfType(Of Button)()
AddHandler b.Click, AddressOf Btnx_Click
Next
End Sub
Private Sub Btnx_Click(sender As Object, e As EventArgs)
' اكتب ما تريده في الحدث
' هنا نختار الباتون بناء علي التكست الخاص به
' ثم نحدد ما يجب أن يحدث عند الضغط علي الباتون
Dim Btnx As Button = CType(sender, Button)
Select Case Btnx.Name
Case "Btnx1"
Text = "Sorax"
Case "Btnx2"
Case "Btnx3"
Case "Btnx4"
Close()
End Select
End Sub
End Class
لا تحتاج لتحديد Location لاداة Panel لان الاداة FlowLayoutPanel هي من تحدد مكانها بشكل تلقائي
كود :
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 0 To 3
Dim Panx As New Panel
Panx.Size = New Size(111, 111)
Panx.BackColor = Color.Silver
FlowLayoutPanel1.Controls.Add(Panx)
Dim Picx As New PictureBox
Picx.Size = New Size(50, 50)
Picx.Location = New Point(30, 5)
Picx.BackColor = Color.White
Panx.Controls.Add(Picx)
Dim Labx As New Label
Labx.Size = New Size(111, 15)
Labx.Location = New Point(0, 63)
Labx.Text = "{NAME}"
Labx.TextAlign = ContentAlignment.TopCenter
Panx.Controls.Add(Labx)
Dim Btnx As New Button
Btnx.Size = New Size(100, 25)
Btnx.Location = New Point(5, 85)
Btnx.Name = "Btnx" & (i + 1).ToString
Btnx.BackColor = Color.White
Btnx.Text = "Send"
AddHandler Btnx.Click, AddressOf Btnx_Click
Panx.Controls.Add(Btnx)
Next
End Sub
