首先command的style要設(shè)為1,否則無法改變
創(chuàng)新互聯(lián)公司專注于吉安網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供吉安營銷型網(wǎng)站建設(shè),吉安網(wǎng)站制作、吉安網(wǎng)頁設(shè)計、吉安網(wǎng)站官網(wǎng)定制、小程序制作服務(wù),打造吉安網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供吉安網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
然后在backcolor設(shè)置顏色
按鈕的字體顏色不能改
如果想改字體顏色,簡單點可以用image做按鈕。
如果一定要,請看:
在工程中添加以下模塊(Module):
Module modExtButton.bas
Option Explicit
您好,這種方法可以通過按鈕的MouseDown和MouseUp事件來實現(xiàn),比如說,當(dāng)單擊按鈕RedColor(RedColor為這個按鈕的Name屬性的屬性值)的時候,要使按鈕的顏色變成紅色,這可以在代碼視圖中的控件選擇下拉列表中選擇RedColor這個控件,然后在右邊的事件下拉列表中選擇MouseDown事件(當(dāng)按下鼠標時發(fā)生),這時,Visual Studio會自動生成如下代碼:
Private Sub RedColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RedColor.MouseDown
End Sub
接下來就在當(dāng)前生成的代碼中寫入如下代碼:
RedColor.BackColor = Color.FromArgb(255, 0, 0)
這句代碼的作用是利用Color下的FromArgb方法來設(shè)置RGB顏色參數(shù),在RGB顏色系統(tǒng)中,R代表紅色,G代表綠色,B代表藍色,根據(jù)這三種顏色的不同程度的調(diào)和,就會得到不同的顏色,如果您要得到深色的天藍色,則可以設(shè)置FromArgb(0, 191, 255),這個顏色轉(zhuǎn)換為HTML中的RGB顏色就是#00BFFF。
當(dāng)然顏色還原最好是寫在MouseUp事件里面,這樣就不必在單擊其他按鈕時來還原上一次按下的按鈕的顏色,在這里,為了方便描述,我們假設(shè)按鈕的默認顏色為白色,也就是FromArgb方法設(shè)置為FromArgb(255, 255, 255)的時候,所標示的顏色就是白色
所以選擇了RedColor按鈕的MouseUp事件后,Visual Studio會自動生成下列代碼:
Private Sub RedColor_MouseUp(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RedColor.MouseUp
End Sub
MouseUp的含義是當(dāng)鼠標彈起時發(fā)生,所以在這個事件就可以設(shè)置按鈕顏色的還原,即添加下列代碼來實現(xiàn):
RedColor.BackColor = Color.FromArgb(255, 255, 255)
當(dāng)然,這就編寫好了一個按鈕按下時變色,回彈時還原的功能,至于另外一個按鈕的功能,這與這個按鈕的功能一樣,只是代碼有一些細微的差別而已,假設(shè)這個按鈕的Name屬性的屬性值為BlueColor,相應(yīng)的代碼對應(yīng)如下:
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown
BlueColor.BackColor = Color.FromArgb(0, 0, 255) '藍色的FromArgb
End Sub
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown
BlueColor.BackColor = Color.FromArgb(255, 255, 255)
End Sub
另外,為了避免代碼的冗余,可以將RedColor和BlueColor的MouseUp事件進行合并,這合并后的代碼如下:
Private Sub BlueColor_MouseDown(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BlueColor.MouseDown, RedColor.MouseUp
BlueColor.BackColor = Color.FromArgb(255, 255, 255)
RedColor.BackColor = Color.FromArgb(255, 255, 255)
End Sub
當(dāng)然,這個你只要分析了控件事件代碼的基本結(jié)構(gòu),一切就一目了然了,控件事件代碼的基本結(jié)構(gòu)如下:
[作用域] Sub 事件名([參數(shù)列表]) Handles 控件事件1 [, 控件事件2, 控件事件3...]
[事件代碼區(qū)域]
End Sub
如果此回答對您有幫助,別忘了采納哦,如果沒有解決您的問題,您可以在互聯(lián)網(wǎng)上尋找更多關(guān)于此問題的解決方案,謝謝!
這篇文章介紹了VB.NET設(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
"錯誤!不支持此模式!"
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
分享標題:vb.net設(shè)置顏色 vb窗體背景顏色代碼
文章路徑:http://jinyejixie.com/article34/ddopose.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、網(wǎng)站排名、ChatGPT、外貿(mào)建站、云服務(wù)器、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)