📄 例[6-4].frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "例[6-4] 直方图"
ClientHeight = 2940
ClientLeft = 60
ClientTop = 345
ClientWidth = 3510
LinkTopic = "Form1"
ScaleHeight = 2940
ScaleWidth = 3510
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "绘直方图"
Height = 375
Left = 1800
TabIndex = 1
Top = 2400
Width = 1335
End
Begin VB.CommandButton Command1
Caption = "输入4个数据"
Height = 375
Left = 240
TabIndex = 0
Top = 2400
Width = 1335
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Label1"
Height = 255
Index = 3
Left = 0
TabIndex = 5
Top = 1440
Visible = 0 'False
Width = 615
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Label1"
Height = 255
Index = 2
Left = 0
TabIndex = 4
Top = 1200
Visible = 0 'False
Width = 615
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Label1"
Height = 255
Index = 1
Left = 0
TabIndex = 3
Top = 960
Visible = 0 'False
Width = 615
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Label1"
Height = 255
Index = 0
Left = 0
TabIndex = 2
Top = 720
Visible = 0 'False
Width = 615
End
Begin VB.Shape Shape1
BackColor = &H8000000D&
BorderColor = &H80000006&
FillColor = &H00FF0000&
FillStyle = 0 'Solid
Height = 975
Index = 3
Left = 2040
Top = 1320
Visible = 0 'False
Width = 255
End
Begin VB.Shape Shape1
BackColor = &H8000000D&
BorderColor = &H80000006&
FillColor = &H0000FF00&
FillStyle = 0 'Solid
Height = 975
Index = 2
Left = 1680
Top = 1320
Visible = 0 'False
Width = 255
End
Begin VB.Shape Shape1
BackColor = &H8000000D&
BorderColor = &H80000006&
FillColor = &H0000FFFF&
FillStyle = 0 'Solid
Height = 975
Index = 1
Left = 1320
Top = 1320
Visible = 0 'False
Width = 255
End
Begin VB.Shape Shape1
BackColor = &H8000000D&
BorderColor = &H80000006&
FillColor = &H000000FF&
FillStyle = 0 'Solid
Height = 975
Index = 0
Left = 960
Top = 1320
Visible = 0 'False
Width = 255
End
Begin VB.Line Line2
X1 = 720
X2 = 720
Y1 = 600
Y2 = 2280
End
Begin VB.Line Line1
X1 = 720
X2 = 3000
Y1 = 2280
Y2 = 2280
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim s(4) As Integer '声明存放输入的4个数的数组,被多个事件过程使用,为窗体级变量
Private Sub Command1_Click()
'输入4个整数,并作为刻度值显示在纵坐标上
For k = 1 To 4
s(k) = Val(InputBox("请输入整数")) '输入的四个整数分别放在S(1)、S(2)、S(3)、S(4)中
Label1(k - 1).Caption = s(k) '输入的数值作为标签数组元素的标题,k-1是因为标签数组下标是从0开始
Label1(k - 1).Move Line2.X1 - Label1(k - 1).Width, Line1.Y1 - s(k) '确定标签左上角位置
Label1(k - 1).Visible = True '标签变为可见
Next k
End Sub
Private Sub Command2_Click()
'根据输入的4个数绘出直方图
Dim a As Integer
For k = 1 To 4
Shape1(k - 1).Height = s(k) '确定每个矩形的高度
a = Line1.Y1
Shape1(k - 1).Top = a - Shape1(k - 1).Height '确定形状控件的Top属性,为横坐标的高度
Shape1(k - 1).Visible = True
Next k
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -