嘿,我一直在寻找“如何为按钮添加边框”的答案,直到我的大脑受伤一般的想法是我有一个带有人像的按钮,这个按钮需要一个边框(绿色或红色)表示此人是在线还是离线。我的按钮是在运行时生成的,所以这一切都必须通过代码来实现。另请注意,这些按钮是使用数据库中的行数(dtActive)生成的,这就是我的按钮的生成方式:
Public Sub GenerateUsers()
Dim ContactID As Integer = Nothing
Dim FirstName As String = ""
Dim LastName As String = ""
Dim FullName As String = ""
Dim INTwidth As Integer = Nothing
Dim TextRendering As Size
dim CordX As Integer = 20
Dim CordY As Integer = 30
Dim RunThrough As Integer= 0
Dim tileLine As integer = 1
For Each Row As DataRow In dtActive.Rows
ContactID = Row(0)
FirstName = Row(1)
LastName = Row(3)
FullName = FirstName & " " & LastName
TextRendering = TextRenderer.MeasureText(FullName, Font)
INTwidth = TextRendering.Width
Dim NewLabel As New Label()
With NewLabel
.Parent = Me
.Text = FullName.ToString
.Location = New Point(CordX + 5, CordY + 5)
.Name = "Label" & ContactID
.AutoSize = False
.Size = New System.Drawing.Size(INTwidth, 20)
Me.GroupBox1.Controls.Add(NewLabel)
End With
Dim LogOnBtn As New Button
With LogOnBtn
.Parent = Me
.Location = New Point(CordX, CordY)
.Name = "Tile" & ContactID
.Size = New System.Drawing.Size(140, 140)
.Text = Nothing
Me.GroupBox1.Controls.Add(LogOnBtn)
AddHandler LogOnBtn.Click, AddressOf LogInOut
Try
.BackgroundImage = System.Drawing.Bitmap.FromFile(Row(17).ToString) 'System.Drawing.Bitmap.FromFile(Row(17).ToString)
.BackColor = Color.Red
.FlatStyle = FlatStyle.Flat
.BackgroundImageLayout = ImageLayout.Zoom
Catch ex As Exception
End Try
End With
CordX += 145
RunThrough += 1 'this ensures that once 3 buttons(tiles) have been made, next 3 will be on a new line
If RunThrough = 3 Then
CordX = 20
CordY += 145
RunThrough = 0
End If
Next
End Sub
这是我的窗体:http: //imageshack.us/photo/my-images/29/2bjm.jpg/
我的想法是它看起来像这样:http: //imageshack.us/photo/my-images/547/otuk.jpg/