vb.net设置颜色 vb自定义颜色

VB.NET设置屏幕分辨率、颜色位数、刷新率 实例代码

这篇文章介绍了VB.NET设置屏幕分辨率、颜色位数、刷新率

创新互联是专业的许昌网站建设公司,许昌接单;提供成都网站设计、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行许昌网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

实例代码,有需要的朋友可以参考一下

复制代码

代码如下:

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如何设置按钮不可控时的字体颜色

首先command的style要设为1,否则无法改变

然后在backcolor设置颜色

按钮的字体颜色不能改

如果想改字体颜色,简单点可以用image做按钮。

如果一定要,请看:

在工程中添加以下模块(Module):

Module modExtButton.bas

Option Explicit

vb.net怎么实现单击数字区域的按钮使按钮变红色,单击运算符按钮变蓝色同时数字区按钮还原?紧急在线等…

您好,这种方法可以通过按钮的MouseDown和MouseUp事件来实现,比如说,当单击按钮RedColor(RedColor为这个按钮的Name属性的属性值)的时候,要使按钮的颜色变成红色,这可以在代码视图中的控件选择下拉列表中选择RedColor这个控件,然后在右边的事件下拉列表中选择MouseDown事件(当按下鼠标时发生),这时,Visual Studio会自动生成如下代码:

Private Sub RedColor_MouseDown(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles RedColor.MouseDown

End Sub

接下来就在当前生成的代码中写入如下代码:

RedColor.BackColor = Color.FromArgb(255, 0, 0)

这句代码的作用是利用Color下的FromArgb方法来设置RGB颜色参数,在RGB颜色系统中,R代表红色,G代表绿色,B代表蓝色,根据这三种颜色的不同程度的调和,就会得到不同的颜色,如果您要得到深色的天蓝色,则可以设置FromArgb(0, 191, 255),这个颜色转换为HTML中的RGB颜色就是#00BFFF。

当然颜色还原最好是写在MouseUp事件里面,这样就不必在单击其他按钮时来还原上一次按下的按钮的颜色,在这里,为了方便描述,我们假设按钮的默认颜色为白色,也就是FromArgb方法设置为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的含义是当鼠标弹起时发生,所以在这个事件就可以设置按钮颜色的还原,即添加下列代码来实现:

RedColor.BackColor = Color.FromArgb(255, 255, 255)

当然,这就编写好了一个按钮按下时变色,回弹时还原的功能,至于另外一个按钮的功能,这与这个按钮的功能一样,只是代码有一些细微的差别而已,假设这个按钮的Name属性的属性值为BlueColor,相应的代码对应如下:

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

当然,这个你只要分析了控件事件代码的基本结构,一切就一目了然了,控件事件代码的基本结构如下:

[作用域] Sub 事件名([参数列表]) Handles 控件事件1 [, 控件事件2, 控件事件3...]

[事件代码区域]

End Sub

如果此回答对您有帮助,别忘了采纳哦,如果没有解决您的问题,您可以在互联网上寻找更多关于此问题的解决方案,谢谢!


网站题目:vb.net设置颜色 vb自定义颜色
文章链接:http://pwwzsj.com/article/ddoophc.html