要么重寫這個(gè)控件的 OnPaint 事件,判斷 BorderStyle 屬性為 FixedSingle 的時(shí)候自繪其他顏色。
創(chuàng)新互聯(lián)于2013年開(kāi)始,先為固陽(yáng)等服務(wù)建站,固陽(yáng)等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為固陽(yáng)企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
要么不重寫,把 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)行效果:
這是隨機(jī)變的,你可以把過(guò)程寫在Timer控件里,就自動(dòng)變了。
Option
Explicit
Private
Sub
Form_click()
BackColor
=
RGB(0,
255,
0)
Width
=
8000
Height
=
8000
Randomize
Cls
Me.ForeColor
=
RGB(Rnd
*
255,
Rnd
*
255,
Rnd
*
255)
Call
drawcircle(ScaleWidth
/
2,
ScaleHeight
/
2,
ScaleWidth
/
6.5)
End
Sub
Private
Sub
drawcircle(x
As
Integer,
y
As
Integer,
r
As
Integer)
Dim
i
As
Integer
If
r
60
Then
Circle
(x,
y),
r
Else
Circle
(x,
y),
r
For
i
=
To
7
Call
drawcircle(x
+
2
*
r
*
Cos(i
*
3.141593
/
4),
y
+
2
*
r
*
Sin(i
*
3.141593
/
4),
r
/
3.5)
Next
i
End
If
End
Sub
要用GreateGrahpics函數(shù),比如要向 Panel1,填充顏色:
Dim g As Graphic=Panel1.CreateGraphics
Dim b as New Brush(Color.Blue)
g.FillRectangle(b,Panel1)
寫的比較粗,意思就是這樣的,你可以邊看幫助邊細(xì)細(xì)完成
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
form1.backcolor =?vbRed
endsub
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
form1.backcolor =?vbGreen
end?sub
擴(kuò)展資料:
VB當(dāng)中的顏色代碼
vbBlack H0 黑色
vbRed HFF 紅色
vbGreen HFF00 綠色
vbYellow HFFFF 黃色
vbBlue HFF0000 蘭色
vbMagenta HFF00FF 洋紅
vbCyan HFFFF00 青色
vbWhite HFFFFFF 白色
vbGrayText H80000011 變灰的(無(wú)效的)文字
vbButtonText H80000012 撳壓按鈕上文字的顏色
vbInactiveCaptionText H80000013 非活動(dòng)標(biāo)題內(nèi)文字的顏色
vb3DHighlight H80000014 三維顯示元素的高亮顏色
vb3DDKShadow H80000015 三維顯示元素的最暗陰影顏色
vb3DLight H80000016 低于 vb3Dhighlight 的 三維次高亮顏色
vb3DFace H8000000F 文字表面的顏色
vb3DShadow? H80000010 文字陰影的顏色
vbInfoText H80000017 提示窗內(nèi)文字的顏色
vbInfoBackground H80000018 提示窗內(nèi)背景的顏色
這篇文章介紹了VB.NET設(shè)置屏幕分辨率、顏色位數(shù)、刷新率
實(shí)例代碼,有需要的朋友可以參考一下
復(fù)制代碼
代碼如下:
Private
Declare
Function
GetDeviceCaps
Lib
"gdi32"
(ByVal
hdc
As
Long,
ByVal
nIndex
As
Long)
As
Long
Private
Declare
Function
ChangeDisplaySettings
Lib
"user32"
Alias
"ChangeDisplaySettingsA"
(lpDevMode
As
Any,
ByVal
dwflags
As
Long)
As
Long
Private
Const
CCDEVICENAME
As
Long
=
32
Private
Const
CCFORMNAME
As
Long
=
32
Private
Const
DM_BITSPERPEL
As
Long
=
H40000
Private
Const
DM_PELSWIDTH
As
Long
=
H80000
Private
Const
DM_PELSHEIGHT
As
Long
=
H100000
Private
Const
DM_DISPLAYFLAGS
As
Long
=
H200000
Private
Const
DM_DISPLAYFREQUENCY
=
H400000
Private
Const
CDS_FORCE
As
Long
=
H80000000
Private
Const
BITSPIXEL
As
Long
=
12
Private
Const
HORZRES
As
Long
=
8
Private
Const
VERTRES
As
Long
=
10
Private
Const
VREFRESH
=
116
Private
Type
DEVMODE
dmDeviceName
As
String
*
CCDEVICENAME
dmSpecVersion
As
Integer
dmDriverVersion
As
Integer
dmSize
As
Integer
dmDriverExtra
As
Integer
dmFields
As
Long
dmOrientation
As
Integer
dmPaperSize
As
Integer
dmPaperLength
As
Integer
dmPaperWidth
As
Integer
dmScale
As
Integer
dmCopies
As
Integer
dmDefaultSource
As
Integer
dmPrintQuality
As
Integer
dmColor
As
Integer
dmDuplex
As
Integer
dmYResolution
As
Integer
dmTTOption
As
Integer
dmCollate
As
Integer
dmFormName
As
String
*
CCFORMNAME
dmUnusedPadding
As
Integer
dmBitsPerPel
As
Integer
dmPelsWidth
As
Long
dmPelsHeight
As
Long
dmDisplayFlags
As
Long
dmDisplayFrequency
As
Long
End
Type
Private
Sub
cmdChangeDesktopMode_Click()
Dim
DM
As
DEVMODE
With
DM
.dmPelsWidth
=
CInt(txtNewWidth.Text)
.dmPelsHeight
=
CInt(txtNewHeight.Text)
.dmBitsPerPel
=
CInt(txtNewColor.Text)
.dmDisplayFrequency
=
CInt(txtNewFreq.Text)
.dmFields
=
DM_PELSWIDTH
Or
DM_PELSHEIGHT
Or
DM_BITSPERPEL
Or
DM_DISPLAYFREQUENCY
.dmSize
=
LenB(DM)
End
With
If
ChangeDisplaySettings(DM,
CDS_FORCE)
Then
MsgBox
"錯(cuò)誤!不支持此模式!"
End
If
End
Sub
Private
Sub
Form_Load()
txtOldWidth.Text
=
GetDeviceCaps(Me.hdc,
HORZRES)
txtOldHeight.Text
=
GetDeviceCaps(Me.hdc,
VERTRES)
txtOldColor.Text
=
GetDeviceCaps(Me.hdc,
BITSPIXEL)
txtOldFreq.Text
=
GetDeviceCaps(Me.hdc,
VREFRESH)
End
Sub
繪制線條采用Draw開(kāi)頭的方法,顏色參數(shù)用Pen類;
繪制有填充色的封閉圖形采用Fill開(kāi)頭的方法,顏色參數(shù)用Brush類;
例如:
'繪制一個(gè)實(shí)心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃矩形區(qū)域內(nèi)
Me.CreateGraphics.FillEllipse(New SolidBrush(Color.Orange), 200, 200, 100, 100)
'繪制一個(gè)空心圓,該圓在:直線x=200,y=200,x=200+100,y=200+100所劃矩形區(qū)域內(nèi)
Me.CreateGraphics.DrawEllipse(New Pen(Color.Black), 200, 200, 100, 100)