工程里面添加一個(gè)類,命名為myGroupBox,代碼如下:
儋州網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
Imports System.ComponentModel
Imports System.Drawing.Drawing2D
Public Class myGroupBox
Inherits GroupBox
Public Sub New()
MyBase.BackColor = Color.Transparent
End Sub
Browsable(False) _
Public Overrides Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(value As Color)
MyBase.BackColor = value
End Set
End Property
Private m_backColor As Color = Color.Transparent
Public Property ActualBackColor() As Color
Get
Return Me.m_backColor
End Get
Set(value As Color)
Me.m_backColor = value
End Set
End Property
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)
Dim borderRect As Rectangle = e.ClipRectangle
borderRect.Y += tSize.Height / 2
borderRect.Height -= tSize.Height / 2
Dim gPath As GraphicsPath = CreatePath(0, borderRect.Y, CSng(Me.Width - 1), borderRect.Height - 1, 5, True, _
True, True, True)
e.Graphics.FillPath(New SolidBrush(ActualBackColor), gPath)
e.Graphics.DrawPath(New Pen(Me.BackColor), gPath)
borderRect.X += 6
borderRect.Y -= 7
e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), borderRect)
End Sub
Public Function CreatePath(x As Single, y As Single, width As Single, height As Single, radius As Single, _
RoundTopLeft As Boolean, RoundTopRight As Boolean, RoundBottomRight As Boolean, RoundBottomLeft As Boolean) As GraphicsPath
Dim xw As Single = x + width
Dim yh As Single = y + height
Dim xwr As Single = xw - radius
Dim yhr As Single = yh - radius
Dim xr As Single = x + radius
Dim yr As Single = y + radius
Dim r2 As Single = radius * 2
Dim xwr2 As Single = xw - r2
Dim yhr2 As Single = yh - r2
Dim p As New GraphicsPath()
p.StartFigure()
'Top Left Corner
If RoundTopLeft Then
p.AddArc(x, y, r2, r2, 180, 90)
Else
p.AddLine(x, yr, x, y)
p.AddLine(x, y, xr, y)
End If
'Top Edge
p.AddLine(xr, y, xwr, y)
'Top Right Corner
If RoundTopRight Then
p.AddArc(xwr2, y, r2, r2, 270, 90)
Else
p.AddLine(xwr, y, xw, y)
p.AddLine(xw, y, xw, yr)
End If
'Right Edge
p.AddLine(xw, yr, xw, yhr)
'Bottom Right Corner
If RoundBottomRight Then
p.AddArc(xwr2, yhr2, r2, r2, 0, 90)
Else
p.AddLine(xw, yhr, xw, yh)
p.AddLine(xw, yh, xwr, yh)
End If
'Bottom Edge
p.AddLine(xwr, yh, xr, yh)
'Bottom Left Corner
If RoundBottomLeft Then
p.AddArc(x, yhr2, r2, r2, 90, 90)
Else
p.AddLine(xr, yh, x, yh)
p.AddLine(x, yh, x, yhr)
End If
'Left Edge
p.AddLine(x, yhr, x, yr)
p.CloseFigure()
Return p
End Function
End Class
工具欄會(huì)出現(xiàn)一個(gè)myGroupBox控件,放入窗體,你會(huì)發(fā)現(xiàn)邊框沒了。
可以通過FlatStyle 屬性來改變其邊框
例如:
Button1.FlatStyle = FlatStyle.Flat
Button1.FlatStyle = FlatStyle.Popup
你把 選項(xiàng)卡 拖到屏幕外面不就行了 只顯示選項(xiàng)卡內(nèi)東西 周圍邊緣都不要了 每個(gè)選項(xiàng)卡內(nèi)配合labl 或按鈕 標(biāo)識(shí)不就行了。
可以利用font 設(shè)置。設(shè)置方法如下:
TextBox1.Font = New System.Drawing.Font("宋體", 10)
也可以通過字體對(duì)話框來實(shí)現(xiàn) 如:
Private Sub myButton_Click(sender As Object, e As EventArgs)
Dim myFontDialog As FontDialog
myFontDialog = New FontDialog()
If myFontDialog.ShowDialog() = DialogResult.OK Then
' Set the control's font.
myDateTimePicker.Font = myFontDialog.Font
End If
End Sub
如果要做漂亮的界面的話,我建議你用WPF來做。所有的控件都可以用模板來定義樣式。
虛線的話,只需要定義一個(gè)矩形,設(shè)置一個(gè)屬性就可以了。前提是,WPF應(yīng)用程序只能用VS2008或者VS2010來做
要么重寫這個(gè)控件的 OnPaint 事件,判斷 BorderStyle 屬性為 FixedSingle 的時(shí)候自繪其他顏色。
要么不重寫,把 BorderStyle 設(shè)為 None,直接在這個(gè)控件的 Paint 事件里自繪邊框,例如:
Private?Sub?Label1_Paint(sender?As?Object,?e?As?PaintEventArgs)?Handles?Label1.Paint
e.Graphics.DrawRectangle(Pens.Red,?New?Rectangle(Label1.DisplayRectangle.X,?Label1.DisplayRectangle.Y,?Label1.DisplayRectangle.Width?-?1,?Label1.DisplayRectangle.Height?-?1))
End?Sub
運(yùn)行效果: