VB程序设计课程实验报告(样本参考一) 下载本文

(十)菜单设计和多文档界面

一、 实验目的和要求 二、 实验内容和原理

设计如图所示的简易画板。在窗体上画一个图片框、一个命令按钮和一组单选按钮。请编写适当的事件过程,是程序运行时,选择相应单选按钮,在图片框上可以实现相应功能。如选择“画直线”单选按钮。可用鼠标在图片框上画一条直线。单击命令按钮,则清除图片框内容。

三、 实验环境

Microsoft Visual Basic 6.0 中文版

四、 算法描述及实验步骤

Dim a, b As Integer

Private Sub Command1_Click() Picture1.Cls End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Option1.Value = True Then a = X b = Y

ElseIf Option2.Value = True Then a = X b = Y

ElseIf Option3.Value = True Then a = X b = Y

ElseIf Option4.Value = True Then a = X b = Y End If End Sub

17 Private Sub Picture1_Mouseup(Button As Integer, Shift As Integer, X As Single, Y As Single) Randomize Dim temp As Single If Round(Rnd) = 1 Then temp = Int(4 * Rnd) Else

temp = 1 Int(4 * Rnd + 1) End If

If (Option1.Value = True) Then Picture1.Line (a, b)-(X, Y) ElseIf Option2.Value = True Then Picture1.Line (a, b)-(X, Y), , B ElseIf Option3.Value = True Then

Picture1.Circle (a, b), Sqr((X - a) ^ 2 + (Y - b) ^ 2) ElseIf Option4.Value = True Then

Picture1.Circle (a, b), Sqr((X - a) ^ 2 + (Y - b) ^ 2), , , , temp End If End Sub

五、 调试过程

无错误

六、 实验结果

18