📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 5610
ClientLeft = 60
ClientTop = 450
ClientWidth = 9615
LinkTopic = "Form1"
ScaleHeight = 5610
ScaleWidth = 9615
StartUpPosition = 3 '窗口缺省
Begin VB.ListBox List1
Height = 1500
Left = 5640
TabIndex = 1
Top = 1320
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 1455
Left = 960
TabIndex = 0
Top = 600
Width = 1575
End
Begin VB.Shape Shape1
Height = 1815
Left = 720
Top = 3120
Width = 4215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Min = List1.List(0) '这里获取最大 最小值 作为曲线的最高点和最低点=====
Max = List1.List(0)
For i = 1 To List1.ListCount - 1
If List1.List(i) = "" Then Exit For
If Min < Val(List1.List(i)) Then Min = Min Else Min = Val(List1.List(i))
If Max > Val(List1.List(i)) Then Max = Max Else Max = Val(List1.List(i))
Next i
'=============================================================================
X = Shape1.Left '记录的起始的横坐标
y = Shape1.Top + Shape1.Height '记录起始的竖坐标
h = Shape1.Height '记录总高度
w = Shape1.Width / 31 '记录每次横坐标移动的数值
For i = 0 To List1.ListCount - 2 '循环绘制曲线
If List1.List(i) = "" Then Exit For '这里判断若有项数据空就退出循环
'重点看这句: 画线 x=起始横坐标点 y=起始坐标-(当前数据-最小数据)除以 最大最小差[这里相当于获取位置的比例] 乘以高度
'说不太清楚 请仔细体会 明白这句的作用 这个例题你就看懂了
Me.Line ((X), y - Int((List1.List(i) - Min) / (Max - Min) * h))-(X + w, y - Int((List1.List(i + 1) - Min) / (Max - Min) * h))
'下面这句 改变了起始点的位置 下次可以继续从这里画起
X = X + w
Next i
End Sub
Private Sub Form_Load()
Randomize '让程序真正的随机
For i = 0 To 30 '循环向list内添加31个数据
a = Int(Rnd * 80 + 30)
List1.AddItem a
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -