 |
|
VB.NET จะสร้างสร้าง button แบบ array ในขณะ runtime ได้อย่างไรครับ |
|
 |
|
|
 |
 |
|
อันนี้สร้าง Label
บนฟอร์มต้องเอา Panel Control มาวางไว้ด้วย
ในที่นี้ชื่อ Panel1
Code (VB.NET)
Public Class Form3
Private Const C_DIFF_X = 30
Private Const C_DIFF_Y = 20
Private Const C_ROW = 24
Private Const C_COLUMN = 50
Private lbl_size As New Size(C_DIFF_X, C_DIFF_Y)
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lbl As Label
For n = 0 To C_ROW * C_COLUMN - 1
lbl = New Label
lbl.Size = lbl_size
lbl.Location = New Point((n Mod C_COLUMN) * C_DIFF_X, (n \ C_COLUMN) * C_DIFF_Y)
lbl.BackColor = System.Drawing.Color.FromArgb(CType(CType(192, Byte), Integer), CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer))
lbl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
lbl.Name = "A" & n
lbl.Text = (n \ C_COLUMN).ToString & "-" & (n Mod C_COLUMN)
AddHandler lbl.Click, AddressOf Me.Label_Click
Me.Panel1.Controls.Add(lbl)
Next
End Sub
Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim st As String
Dim lbl As Label = CType(sender, Label)
st = "Name: " & lbl.Name
st &= vbCrLf & "Text: " & lbl.Text
MessageBox.Show(st)
End Sub
End Class
|
 |
 |
 |
 |
Date :
2010-11-26 16:58:50 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอรันโปรแกรม ก็จะได้หน้าตาแบบนี้

พอคลิกที่ Label
ก็จะได้ Message

|
 |
 |
 |
 |
Date :
2010-11-26 17:01:40 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2010-11-28 12:44:47 |
By :
Cyg |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ สำหรับ ความรู้ดีๆๆ
|
 |
 |
 |
 |
Date :
2011-07-24 17:59:33 |
By :
dew |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีแบบแต่ละ Label เคลื่อนย้ายได้ปะครับ
|
 |
 |
 |
 |
Date :
2012-07-19 22:07:02 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|