1.2 任务与分析
本段应详细阐述所选设计题目任务的具体内容及具体要求,分析设计软件的预期功能和涉及的VB知识点。
简易绘图板这小程序要求能完成简单的图形绘制,如直线、圆、矩形、椭圆;能实现基本的线型线宽的改变;能实现绘图界面的清空;能通过菜单栏实现文件的保存、打开以及在帮助菜单中找到使用说明和其它问题解决
。
该程序中涉及:
各种基本绘图语句的运用
条件语句的使用
控件数组的创建和使用
active控件的创建和使用
2
设计
设计一个类似于windows附件中绘图板的程序
画直线状态下点鼠标左键位置为直线的起点,松开鼠标所在位置点为终点。
画圆状态下圆心,松开鼠标所在位置点为圆上一点。
画矩形状态下点鼠标左键位置和松开鼠标所在位置点为所画矩形的两个对角点。
加载窗体默认绘图为黑色细实线画直线,通过点击界面上的相应控件改变线型、颜色、粗细。
点击“涂鸦”按钮实现自由绘画
点击“清空”按钮清楚图纸上的内容
在菜单栏中添加保存、打开和帮助项
3 界面设计
界面设计结果如下图
界面设计步骤
1、Ctrl+E打开菜单栏编辑器添加菜单项目
2、添加可见控件
控件名
要更改的属性名
更改后的属性值
Picture3(0)
backcolor
选黑色
Picture3(1)
backcolor
选红色
Picture3(2)
backcolor
选黄色
Picture3(3)
backcolor
选蓝色
Frame1
Caption
颜色
Frame2
Caption
线型
Frame3
Caption
线宽
Command1
Caption
清空
Command2
Caption
涂鸦
CommonDialog1
Filename
我的图画
CommonDialog1
Filter
.bmp
3、添加图片框控件里的line及shape
先在相应位置画好图形再按下表更改属性
控件名
要更改的属性名
更改后的属性值
Line2
borderstyle
2-Dash
Line3
borderstyle
3-Dot
Line6
borderwidth
2
Line7
borderwidth
3
Shape1
shape
3-Circle
Shape2
shape
0-Rectangle
Shape3
shape
2-Oval
4 代码设计及程序调试
1、声明必须的全局变量
Dim reX As Integer, reY As Integer, k As Integer, xx As Integer, xk As Integer, ys As Integer, tuya As Integer ‘声明必要的全局变量
2、清空绘图板上的图像
Private Sub Command1_Click() ‘清空绘图板
Picture1.Cls
End Sub
3、涂鸦状态选择
Private Sub Command2_Click() ‘涂鸦状态选择
If tuya = 0 Then ‘如果不是涂鸦状态则进入涂鸦状态,是则退出
tuya = 1
Else
tuya = 0
End If
End Sub
4、拾取起点坐标
Sub picture1_mousedown(button As Integer, shift As Integer, X As Single, y As Single)
reX = X ‘拾取坐标
reY = y
End Sub
5、实现自由绘制
Sub picture1_mousemove(button As Integer, shift As Integer, X As Single, y As Single)
If xk = 0 Then ‘默认线宽为1
xk = 1
End If
If tuya = 1 And button = 1 Then
Picture1.DrawWidth = xk ‘使用线宽
Picture1.DrawStyle = xx ‘使用线型
Picture1.Line (reX, reY)-(X, y), QBColor(ys) ‘画线
reX = X ‘又将当前点坐标赋给reX、reY
reY = y
End If
End Sub
6、绘制图像
Sub picture1_mouseup(button As Integer, shift As Integer, X As Single, y As Single)
If xk = 0 Then
xk = 1
End If有、
Picture1.DrawWidth = xk
Picture1.DrawStyle = xx
If k = 0 And button = 1 Then ‘画直线
Picture1.Line (reX, reY)-(X, y), QBColor(ys)
End If
If k = 1 And button = 1 Then ‘画圆
rrr = Sqr((reX - X) ^ 2 + (reY - y) ^ 2)
Picture1.Circle (reX, reY), rrr, QBColor(ys)
End If
If k = 2 And button = 1 Then ‘画矩形
Picture1.Line (reX, reY)-(X, y), QBColor(ys), B
End If
If k = 3 And button = 1 Then ‘画椭圆
rrr = Sqr((reX - X) ^ 2 + (reY - y) ^ 2)
Picture1.Circle (reX, reY), rrr, QBColor(ys), , , 1 / 3
End If
End Sub
7、选择线型
Private Sub Picture2_Click(Index As Integer) ‘选择线型
xx = Index
End Sub
8、选择颜色
Private Sub Picture3_Click(Index As Integer) ‘选择颜色
If Index = 0 Then
ys = 0
ElseIf Index = 1 Then
ys = 12
ElseIf Index = 2 Then
ys = 14
ElseIf Index = 3 Then
ys = 9
End If
End Sub