用法:改变2个数字参数的值来改变角的弧度,大家可以根据控件的大小自己测试规律
Dim x As New changetextbox(Me.TextBox4, 2, 3, Color.Blue)
Dim y As New changetextbox(Me.TextBox5, 13, 18, Color.Brown)
Class changetextbox
Dim t As TextBox
'Dim d As Integer = 13
'Dim tj As Integer = 18
Dim d As Integer = 13
Dim tj As Integer = 18
Dim cor As Color
Sub New(ByVal t As Control, ByVal d As Integer, ByVal tj As Integer, ByVal cor As Color)
Me.t = t
Me.d = d
Me.tj = tj
Me.cor = cor
Dim p As Control = t.Parent
Me.t.BorderStyle = BorderStyle.None
t.BackColor = p.BackColor
AddHandler p.Paint, AddressOf Me.Panel1_Paint
End Sub
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim x1 As Point = New Point(t.Location.X - 1, t.Location.Y - 1)
Dim x2 As Point = New Point(t.Location.X + t.Width, t.Location.Y + t.Height)
Dim r As Single = Math.Sqrt(Math.Pow(tj, 2) + Math.Pow(tj - d, 2))
Dim p As Pen = New Pen(cor)
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawLine(p, x1, New Point(x2.X, x1.Y)) '上
e.Graphics.DrawLine(p, New Point(x1.X, x2.Y), x2) '下
e.Graphics.DrawLine(p, New Point(x1.X - d, x1.Y + d), New Point(x1.X - d, x2.Y - d)) '左
e.Graphics.DrawLine(p, New Point(x2.X + d, x1.Y + d), New Point(x2.X + d, x2.Y - d))
Dim zsdd As New Point(x1.X - d + tj - r, x1.Y + tj - r) '左上角
Dim zxdd As New Point(x1.X + -d + tj - r, x2.Y - tj - r) '左下角
Dim ysdd As New Point(x2.X + d - tj - r, x1.Y + tj - r) '右上角
Dim yxdd As New Point(x2.X + d - tj - r, x2.Y - tj - r) '右下角
'Dim tj As Single = r * Math.Sin(Math.PI / 2 / 2)
Dim ab As Single = Math.Atan((tj - d) / tj) / Math.PI * 180
'MsgBox(ab)
'Dim rc As New Rectangle(zsdd, New Size(Math.Round(r * 2), Math.Round(r * 2)))
'e.Graphics.DrawRectangle(Pens.Blue, rc)
e.Graphics.DrawArc(p, zsdd.X, zsdd.Y, r * 2, r * 2, 180 + ab, (45 - ab) * 2) '左上
e.Graphics.DrawArc(p, zxdd.X, zxdd.Y, r * 2, r * 2, 90 + ab, (45 - ab) * 2) '左下
e.Graphics.DrawArc(p, ysdd.X, zsdd.Y, r * 2, r * 2, 270 + ab, (45 - ab) * 2) '右上
e.Graphics.DrawArc(p, yxdd.X, yxdd.Y, r * 2, r * 2, ab, (45 - ab) * 2) '右上
'Dim r As New Rectangle(40, 50, 150, 50) ';//定义一个Rectangle结构
'e.Graphics.DrawArc(Pens.Red, r, 180, 180)
End Sub
End Class