信息系统与数据库技术全书实验参考答案(4)

2019-04-13 23:13

Form1 Text Text Text Text 第一个VB.NET实验 显示文本信息 改变背景色 结束 Textbox1 Text Button1 Button2 Button3

Private Sub Button1_Click(……) Handles Button1.Click

TextBox1.Text = \我喜欢VB.NET,因为它简单易学,使用方便。\End Sub

Private Sub Button2_Click(……) Handles Button2.Click TextBox1.BackColor = Color.Yellow End Sub

Private Sub Button3_Click(……) Handles Button3.Click End End Sub

2.试编一程序,将华氏温度转换为摄氏温度。程序运行时,单击窗体上【开始】按钮,提示输入华氏温度(用InputBox函数),然后将华氏温度转化为摄氏温度,并在窗体上显示华氏温度和摄氏温度。转换公式为:C=5/9*(F-32),其中,F是华氏温度,C是摄氏温度。程序界面如图2所示。

窗体对象属性 对象 Button1 Label1 Label2 Label3 Label4

Private Sub Button1_Click(……) Handles Button1.Click Dim c As Single Dim f As Single

f = Val(InputBox(\请输入华氏温度\ c = 5.0 / 9 * (f - 32)

Label3.Text = Format(f, \ Label4.Text = Format(c, \End Sub

属性 Text Text Text Text Text 设置值 开始 华氏温度 摄氏温度 Textbox1 Text

3.设计一程序,窗体界面如图3所示。要求在程序运行时,根据选择可以改变文本框内文本的字体、字形等。

图4

图3 图4

窗体对象属性

对象 Textbox1 Button1 GroupBox1 GroupBox 2 属性 Text Text Text Text 退出 颜色设置 字形设计 设置值 RadioButton1 Text 红色 Checked True RadioButton2 Text RadioButton3 Text CheckBox1 CheckBox2 CheckBox3

Private Sub Form1_Load(……) Handles MyBase.Load TextBox1.ForeColor = Color.Red

TextBox1.Font = New Font(TextBox1.Font.FontName, 12, FontStyle.Underline)

TextBox1.Text = \是面向对象的程序设计语言,简单易学,深受程序设计者喜欢\ TextBox1.SelectionStart = 0 End Sub

Private Sub RadioButton1_CheckedChanged(……) Handles RadioButton1.CheckedChanged, _ RadioButton2.CheckedChanged, RadioButton3.CheckedChanged If RadioButton1.Checked Then TextBox1.ForeColor = Color.Red ElseIf RadioButton2.Checked Then TextBox1.ForeColor = Color.Green Else

TextBox1.ForeColor = Color.Blue End If End Sub Private

Sub

CheckBox1_CheckedChanged(……)

Handles

CheckBox1.CheckedChanged,

CheckBox2.CheckedChanged, CheckBox3.CheckedChanged Dim newFontStyle As System.Drawing.FontStyle newFontStyle = FontStyle.Regular If CheckBox1.Checked Then

newFontStyle = newFontStyle + FontStyle.Underline End If

If CheckBox2.Checked Then

newFontStyle = newFontStyle + FontStyle.Bold

绿色 蓝色 Text 下划线 Checked True Text Text 粗体 斜体 End If

If CheckBox3.Checked Then

newFontStyle = newFontStyle + FontStyle.Italic End If

TextBox1.Font = New Font(TextBox1.Font.Name, TextBox1.Font.Size, newFontStyle) End Sub

Private Sub Button1_Click(……) Handles Button1.Click End End Sub

4. 设计一程序,其界面如图4所示,程序运行时,单击“添加”按钮,可将文本框的内容添加到列表框中;单击“删除”按钮,可删除选中的内容;单击“清除”按钮,清除列表框中的所有内容;双击列表框中某一项,该项内容可在文本框中显示。

窗体对象属性

对象 Label1 属性 歌星排行榜 Text 设置值 Textbox1 Text ListBox1 Items 刘德华 周杰伦 张惠妹 Button1 Button2 Button3

Private Sub Button1_Click(……) Handles Button1.Click Dim i As Integer

For i = 0 To ListBox1.Items.Count - 1

If TextBox1.Text = ListBox1.Items(i) Then Exit For End If Next

If i >= ListBox1.Items.Count Then ListBox1.Items.Add(TextBox1.Text) TextBox1.Text = \ End If End Sub

Private Sub Button2_Click(……) Handles Button2.Click ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) End Sub

Private Sub Button3_Click(……) Handles Button3.Click ListBox1.Items.Clear() End Sub

Private Sub ListBox1_DoubleClick(……) Handles ListBox1.DoubleClick

Text Text Text 添加 删除 清除 TextBox1.Text = ListBox1.SelectedItem End Sub

5-2

5.设计一个具有3个窗体的应用程序。其中“算术运算”窗口具有主菜单,菜单内容如图5a、5b所示;“加、减运算”和“乘、除运算”窗口具有弹出式菜单,如图5c、5d所示。应用程序运行时,可从“算术运算”窗口的主菜单中选择“计算加、减”或“计算乘、除”菜单命令,进入“加、减运算”窗口或“乘、除运算”窗口,然后从键盘上输入两个数到文本框中,利用窗体上的弹出式菜单命令求出它们的和、差或乘、除,并显示运算结果。

图5a

图5b 图5c 图5d

窗体Form1对象属性 对象 属性 设置值 Form1 Text 算术运算 MenuItem1 Text 计算 MenuItem2 Text 计算加、减 MenuItem3 Text 计算乘、除 MenuItem4 Text 退出 MenuItem5 Text 结束

窗体Form2对象属性 窗体Form3对象属性 对象 属性 设置值 对象 属性 设置值 Form2 Text 加、减运算 Form3 Text 乘、除运算 ContextMenu ContextMenu1 ContextMenu ContextMenu Label1 Text 第一个数 Label1 Text 第一个数 Label2 Text 第二个数 Label2 Text 第二个数 Label3 Text 计算结果 Label3 Text 运算结果 Textbox1 Text Textbox1 Text Textbox2 Text Textbox2 Text Textbox3 Text Textbox3 Text ContextMenu1 ContextMenu1 MenuItem1 Text 加运算 MenuItem1 Text 乘运算 MenuItem2 Text 减运算 MenuItem2 Text 除运算 MenuItem3 Text 清除 MenuItem3 Text 清除 MenuItem4 Text 返回 MenuItem4 Text 返回 //窗体“算术运算”

Private Sub MenuItem2_Click(……) Handles MenuItem2.Click

图 Dim frm2 As New Form2 Me.Hide() frm2.Show() End Sub

Private Sub MenuItem3_Click(……) Handles MenuItem3.Click Dim frm3 As New Form3 Me.Hide() frm3.Show() End Sub

Private Sub MenuItem5_Click(……) Handles MenuItem5.Click End End Sub

//窗体“加、减运算”

Private Sub MenuItem1_Click(……) Handles MenuItem1.Click

TextBox3.Text = Val(TextBox1.Text.Trim) + Val(TextBox2.Text.Trim) End Sub

Private Sub MenuItem2_Click(……) Handles MenuItem2.Click

TextBox3.Text = Val(TextBox1.Text.Trim) - Val(TextBox2.Text.Trim) End Sub

Private Sub MenuItem3_Click(……) Handles MenuItem3.Click TextBox1.Text = \ TextBox2.Text = \ TextBox3.Text = \End Sub

Private Sub MenuItem4_Click(……) Handles MenuItem4.Click Dim frm1 As New Form1 Me.Hide() End Sub

//窗体“乘、除运算”

Private Sub MenuItem1_Click(……) Handles MenuItem1.Click TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text) End Sub

Private Sub MenuItem2_Click(……) Handles MenuItem2.Click If Val(TextBox2.Text) = 0 Then MsgBox(\除数为0,出错!\ TextBox1.Text = \ TextBox2.Text = \ Exit Sub Else

TextBox3.Text = Format(Val(TextBox1.Text) * 1.0 / Val(TextBox2.Text), \ End If End Sub

Private Sub MenuItem3_Click(……) Handles MenuItem3.Click TextBox1.Text = \


信息系统与数据库技术全书实验参考答案(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:6小学语文教师素养大赛知识问答题目

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: