是否可以在visualbas.net windows窗体应用程序中的文本框周围创建虚线边框?

问题描述 投票:1回答:1

我一直在使用一个代码,允许我在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
vb.net textbox
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.