gpt4 book ai didi

vb.net - Visual Basic : picuter border on a button. 怎么办?

转载 作者:行者123 更新时间:2023-12-02 01:59:15 25 4
gpt4 key购买 nike

嘿,我一直在寻找“如何为按钮添加边框”的答案直到我的大脑受伤一般的想法是我有一个带有人像的按钮,这个按钮需要一个边框(绿色或红色)来指示这个人是在线还是离线。我的按钮是在运行时生成的,因此所有这些都必须通过代码发生。另请注意,这些按钮是使用数据库中的行数生成的 (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/

最佳答案

WinForms 没有像 WPF 那样的边框控件,因此您将不得不使用 GraphicsPath Class 自己绘制边框。 .

这是一个绘制圆角矩形的函数,您需要提供按钮的 x,y 坐标、高度/宽度和圆角的半径值:

Public Sub DrawRoundRect(g As Graphics, p As Pen, x As Single, y As Single, width As Single, height As Single, radius As Single)
Dim gp As New GraphicsPath()

gp.AddLine(x + radius, y, x + width - (radius * 2), y) ' Line
gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90) ' Corner
gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)) ' Line
gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90) ' Corner
gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height) ' Line
gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90) ' Corner
gp.AddLine(x, y + height - (radius * 2), x, y + radius) ' Line
gp.AddArc(x, y, radius * 2, radius * 2, 180, 90) ' Corner

gp.CloseFigure()

g.DrawPath(p, gp)

gp.Dispose()
End Sub

关于vb.net - Visual Basic : picuter border on a button. 怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18135005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com