VB随笔2
1 显示进度条
先弄一个label标签,capation属性设为空白,背景色设为深蓝色
然后弄一个timer控件,同时时间间隔为(Interval):100
Private Sub Timer1_Timer()
Label1.Width = Label1.Width + 20
End Sub
2 设置如何调用鼠标右键菜单
先用菜单管理器弄出一级菜单右键,名为right,二级菜单三个,打开,复制,粘贴
Private Sub Form_MouseUp(Button As String)
If Button = 2 Then
PopupMenu Form1.right
End If
End Sub
3 vb 图形位置设置
Private Sub Form_Load()
Form1.ScaleHeight = 4 '将窗体当前可用高度(去掉标题栏)分为4份
Form1.ScaleWidth = 4 '将窗体当前可用宽度(去掉标题栏)分为4份
Label1.Left = 2 ‘标签左上角点的横坐标,2/4
Label1.Top = 2 ‘标签左上角点的纵坐标,2/4
End Sub
4 新年快乐明信片
Private Sub Form_Click()
Dim x1 As Integer, y1 As Integer, z1 As Integer
FontSize = 24
Scale (-100, 320)-(320, -320)
Cls
Print "新年快乐!"
For i = 1 To 80
DrawWidth = 6
x1 = 320 * Rnd
y1 = 320 * Rnd
If Rnd < 0.5 Then x1 = -x1
If Rnd < 0.5 Then y1 = -y1
PSet (x1, y1), QBColor(Rnd * 15)
Next i
End Sub
----
object.Scale (x1, y1) - (x2, y2)
x1,y1是左上角的坐标
x2,y2是右下角的坐标
比如是(-10,-20)-(10,20),这时x1=-10,x2=10,窗体中从左到右能显示的水平坐标就是从-10到10,同样y1=-20,y2=20,窗体中从上到下能显示的垂直坐标就是从-20到20,原点是0,0,自然就是在中间了。
----
5 正弦函数
Private Sub Form_Click()
Dim x As Single, y As Single, a As Integer
Const pi = 3.14159265
Line (450, 1200)-(4000, 1200) '绘制x坐标轴
Line (4000, 1200)-(3800, 1150) '绘制x坐标轴的上箭头
Line (4000, 1200)-(3800, 1250) '绘制x坐标轴的下箭头
Line (500, 200)-(500, 2000) '绘制y坐标轴
Line (500, 200)-(450, 400) '绘制y坐标轴的左箭头
Line (500, 200)-(550, 400) '绘制y坐标轴的右箭头
For a = 0 To 360
y = (-1) * Sin(a * pi / 180) * 500 + 1200 '设定画点的y坐标
x = a * 8 + 500 '设定画点的x坐标
PSet (x, y), RGB(255, 0, 0)
Next a
Print Tab(19); "正弦函数"
End Sub
6 shape 的几种图形和填充类型 ‘一定要先将shape的index属性设为0
Private Sub Form_Click()
Dim i
Shape1(0).Shape = 0
Shape1(0).FillStyle = 2
For i = 1 To 5
Load Shape1(i)
Shape1(i).Left = Shape1(i - 1).Left + 900
Shape1(i).Shape = i
Shape1(i).FillStyle = i + 2
Shape1(i).Visible = True
Next i
End Sub
7 打开本地文件设置图片显示 ’需要到 工程-控件-部件 添加 Microsoft Common Dialog Control 6.0
然后再在frame界面添加一个CommonDialog控件
Private Sub Command1_Click()
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
End Sub
Private Sub Command2_Click()
Image1.Width = Image1.Width + 150
Image1.Height = Image1.Height + 150
End Sub
Private Sub Command3_Click()
Image1.Width = Image1.Width - 150
Image1.Height = Image1.Height - 150
End Sub
Private Sub Command4_Click()
Image1.Left = Image1.Left - 100
End Sub
Private Sub Command5_Click()
Image1.Left = Image1.Left + 100
End Sub
Private Sub Image1_Click()
End Sub
Private Sub Command6_Click() '打印显示的内容
PrintForm
End Sub