用户界面设计实验.doc





《用户界面设计实验.doc》由会员分享,可在线阅读,更多相关《用户界面设计实验.doc(8页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第7章 用户界面设计实验2班级:俄语2班 学号: 姓名:孙晴一、 实验目的1掌握定时器等控件的重要属性、方法和事件,熟悉它们的使用。2掌握菜单设计与应用。二、实验内容(一)、实例解析:按 下列说明操作,完成程序调试。1、数字时钟设计。思路:在Timer事件中,获取当前时间,并显示在标签上 设计界面 运行界面【步骤】(1)设计应用程序界面:设置1个标签,1个定时器。属性设置:Timer1的Enabled为True,Interval为1000。(2)编写事件代码:Private Sub Timer1_Timer()Label1.Caption = TimeEnd Sub(3)程序的运行及保存。2、
2、闹钟。思路:在Timer事件中:获取当前时间、提取时分秒、将提取的时分秒与文本框中的时分秒进行比对 设计界面 运行界面【步骤】(1)设计应用程序的界面:在窗体上创建5个标签;3个文本框;1个定时器。属性设置:Timer1的Enabled为True,Interval为1000。(2)编写事件代码:Private Sub Form_Load()Text1.Text = : Text2.Text = : Text3.Text = End SubPrivate Sub Timer1_Timer()Label5.Caption = Time Now返回当前日期时间;Time返回当前时间s = Hour(
3、Now)f = Minute(Now)m = Second(Now)t = Times = Hour(t)f = Minute(t)m = Second(t)If Text1.Text = s And Text2.Text = f And Text3.Text = m Then MsgBox 闹钟时间到!End Sub(3)程序的运行及保存。3、计时器。思路:在Timer事件中1. 从文本框获取目前的时分秒,转换为总秒数2. 将总秒数减1,然后再转换为时分秒放入文本框中3. 检查总秒数是否为0,即计时器结束 设计界面 运行界面【步骤】(1)设计应用程序界面:在窗体上创建4个标签;3个文本框;2
4、个命令按钮;1个定时器。属性设置:Timer1的Enabled为False,Interval为1000。(2)编写事件代码:Private Sub Form_Load()Text1.Text = : Text2.Text = : Text3.Text = End SubPrivate Sub Command1_Click()Timer1.Enabled = True End SubPrivate Sub Command2_Click()Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()zms = Val(Text1.Text) * 6
5、0 * 60 + Val(Text2.Text) * 60 + Val(Text3.Text)zms = zms - 1Text1.Text = zms (60 * 60)Text2.Text = (zms - Text1.Text * 60 * 60) 60Text3.Text = zms - Text1.Text * 60 * 60 - Text2 * 60If Text1.Text = 0 And Text2.Text = 0 And Text3.Text = 0 Then Timer1.Enabled = False MsgBox 记时结束!End IfEnd Sub或者:在设计时属性
6、设置为:Timer1的Enabled为True,Interval为0则代码为:Private Sub Command1_Click()Timer1.Interval = 1000End SubPrivate Sub Command2_Click()Timer1.Interval = 0End SubPrivate Sub Timer1_Timer()zms = Val(Text1.Text) * 60 * 60 + Val(Text2.Text) * 60 + Val(Text3.Text)zms = zms - 1Text1.Text = zms (60 * 60)Text2.Text =
7、(zms - Text1.Text * 60 * 60) 60Text3.Text = zms - Text1.Text * 60 * 60 - Text2 * 60If Text1.Text = 0 And Text2.Text = 0 And Text3.Text = 0 Then Timer1.Interval = 0 MsgBox 记时结束!End IfEnd Sub4、菜单设计-上课示例编一程序,进行两个操作数的算术运算练习。设计界面如下: 【步骤】 (1)创建应用程序的用户界面和设置对象属性:a)设计2标签;2文本框;2命令按钮b)利用菜单设计器设计菜单:工具菜单设计器 菜单栏向用
8、户提供功能选择,包括运算数的位数,运算符类型(加、减、乘)和退出程序各菜单项的名称分别为:位数 b1 一位数 b11 两位数 b12三位数 b13运算 b2 加法 b21 减法 b22 乘法 b23退出 b3(2)编写事件代码:Option Explicit 规定所有变量都要显式声明Dim sel1 As Integer, sel2 As StringDim r1 As LongPrivate Sub Form_Load() sel1 = 0 位数标记 sel2 = 运算标记 RandomizeEnd SubPrivate Sub b11_click() sel1 = 1 设置位数标记End
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 用户界面 设计 实验

限制150内