用计算机设置变大的命令按钮 vb,VB教程:命令按钮(CommandButton)

15cff1bb0b12d3e15c2d1b91e2ef36da.png

4、命令按钮(Command Button)

作用:用于开始、中断或结束一个按钮。

(1)常用属性

Caption属性

Style属性

visible =false ' 按钮不可见

enabled=true ' 按钮无效

default =true ' 使按钮成为缺省的“活动按钮”,可用enter键选中

cancel =true ' 使按钮成为缺省的“取消按钮”,可用esc键选中

注意:在一个窗体中,只能有一个命令按钮可以设为缺省的“活动按钮”,也只能有一个命令按钮可以设为缺省的“取消按钮”。

Picture '加载一幅图片

有时.我们可能还需要在命令按钮上显示某个图案以使界面显得活泼生动,要制作这样的按钮,需要设置它的两个属性;styLe属性和Picture属性。我们先将该命令按钮的style属性设置为1(GraPhical),再通过其Picture属性加载一幅图片即可,如图显示了一个带图案的命令按钮。

(2)主要事件

最主要的事件是单击(Click)事件。

(3)常用方法

Print方法:用于在窗体、图片框和打印机上显示文本。其语法格式为:

object.Print [outputlist]

Cls方法:用来清除运行时窗体或图片框所生成的图形和文本。其语法格式为:

object.Cls

Move方法:用于移动窗体或控件,并可以改变其尺寸大小,其语法格式为:

object.Move left, top, width, height

其中:

object:可选项。表示移动窗体或控件。一个对象表达式,其值为“应用于”列表中的一个对象。如果省略object,带有焦点的窗体缺省为 object。

Left:必需项。指示 object 左边的水平坐标 (x-轴)。

Top:可选项。指示 object 顶边的垂直坐标 (y-轴)。

Width:可选项。指示 object 新的宽度。

Height:可选项。指示 object 新的高度。

(4)例子:

见教材P109。计算器应用程序。

代码如下:

Public a, b, result As Double

Public c As Integer

Dim op As String

Dim index As Integer

--------------------------------------------------------------------------------

Private Sub Form_Load()

a = 0

b = 0

Text1.Text =""

End Sub

--------------------------------------------------------------------------------

Private Sub a1_Click()

Text1.Text = Text1.Text & a1.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a2_Click()

Text1.Text = Text1.Text & a2.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a3_Click()

Text1.Text = Text1.Text & a3.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a4_Click()

Text1.Text = Text1.Text & a4.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a5_Click()

Text1.Text = Text1.Text & a5.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a6_Click()

Text1.Text = Text1.Text &a6.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a7_Click()

Text1.Text = Text1.Text & a7.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a8_Click()

Text1.Text = Text1.Text & a8.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a9_Click()

Text1.Text = Text1.Text & a9.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a10_Click()

Text1.Text = Text1.Text & a10.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a11_Click()

Text1.Text =Text1.Text & a11.Caption

End Sub

--------------------------------------------------------------------------------

Private Sub a12_Click()

b = Text1.Text

index = 0

Select Case op

Case +

result = CDbl(a) + CDbl(b)

Text1.Text = CStr(result)

Case -

result = CDbl(a) - CDbl(b)

Text1.Text = CStr(result)

Case *

result = CDbl(a) * CDbl(b)

Text1.Text = CStr(result)

Case /

If CDbl(b) = 0

Then Text1.Text = error

Else

result = CDbl(a) / CDbl(b)

Text1.Text = CStr(result)

End If

End Select

If Text1.Text = error Then Text1.Text = CStr(result)

End Sub

--------------------------------------------------------------------------------

Private Sub b1_Click()

If index = 0 Then a = Text1.Text

index = index + 1

2829f2ca24f0d0090cbba57f30759f23.png

VB教程:命令按钮(CommandButton).doc

下载Word文档到电脑,方便收藏和打印[全文共2409字]

编辑推荐:

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

下载Word文档

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值