我一直在处理一个代码,允许我在vb.net中的文本框周围绘制线条,但这些线条是实线。我想用虚线或虚线来装点应用程序。有没有办法在文本框周围创建虚线,就像你可以在表单上做的那样?我目前使用的代码就是这样..
Dim g As Graphics = e.Graphics
Dim pen As New Pen(Color.Aqua, 2.0)
Dim txtBox As Control
For Each txtBox In Me.Controls
If TypeOf (txtBox) Is TextBox Then
g.DrawRectangle(pen, New Rectangle(txtBox.Location, txtBox.Size))
End If
Next
pen.Dispose()
我还想提一下,我可以在paint事件中使用此代码来获取表单周围的虚线。将它放在文本框周围看起来真的很棒我希望这是可能的!
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle,Color.Aqua, ButtonBorderStyle.Dashed)
编辑:我刚试过这段代码似乎是在绘制虚线矩形,但它们并没有绕过我的文本框,所以不确定如何解决它。
Dim txtBox As Control
For Each txtBox In Me.Controls
If TypeOf (txtBox) Is TextBox Then
ControlPaint.DrawBorder(e.Graphics, txtBox.ClientRectangle, txtBox.ForeColor, ButtonBorderStyle.Dashed)
End If
Next
答案 0 :(得分:2)
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
For Each txtBox As Control In Me.Controls
If TypeOf (txtBox) Is TextBox Then
Dim borderRectangle As Rectangle = New Rectangle(txtBox.Location, txtBox.Size)
borderRectangle.Inflate(1, 1)
ControlPaint.DrawBorder(e.Graphics, borderRectangle, txtBox.ForeColor, ButtonBorderStyle.Dashed)
End If
Next
End Sub