1、11.新建工程,界面如下图,将窗体名称改为 f1,标题属性为“我的第一个工程” , Text2 允许多行,三个命令按钮名称分别为 C1、C2 、C3,单击 C1 按钮将 Text1 的字体改为黑体,Text2 的字体改为隶书。 单击 C2 按钮将 Text1 的文字颜色改为红色,Text2 的背景颜色改为蓝色。单击 C3 按钮结束程序运行。Private Sub Command1_Click()Text1.Font = 黑体End SubPrivate Sub Command2_Click()Text1.ForeColor = vbRedText2.ForeColor = vbBlueEnd
2、SubPrivate Sub Command3_Click()EndEnd Sub2.新建工程,界面如上图,运行时,鼠标在“改变窗体颜色”按钮上按下时使窗体背景色变为红色,鼠标抬起时使窗体背景色变为绿色。鼠标在窗体空白地方按下时使 Text1 的内容为“在窗体上按下了鼠标” ,鼠标抬起时使 Text1 的内容为“在窗体上抬起了鼠标” 。Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Form1.BackColor = vbRedEnd SubPrivate
3、Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Form1.BackColor = vbGreenEnd SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Text1.Text = “在窗体上按下了鼠标“End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X A
4、s Single, Y As Single)Text1.Text = “在窗体上抬起了鼠标“End Sub3.新建工程,界面如下图,运行时,在文本框 Text1 中输入内容的同时,在文本框 Text2、Text3 中显示相同的内容,但字体不同(字体自定) 。Private Sub Command1_Click() Text1.Text = “Text2Text12Text2.Text = “Text3.Text = “End SubPrivate Sub Command2_Click()EndEnd SubPrivate Sub Text1_Change()Text2.Text = Text1
5、.TextText3.Text = Text1.TextEnd Sub注:“字体不同”可以在属性那调“Font”4. 设计一个窗体,如上图所示。当单击某个命令按钮时,对文本框中的文字完成相应的设置。其中,每单击一次“增大”或“缩小”按钮将使文本框中的文字增大或缩小 5 磅, “粗体”按钮将使文本框中的文字加粗, “斜体”按钮将使文本框中的文字倾斜, “下划线”按钮将使文本框中的文字加下划线, “删除线”按钮将使文本框中的文字加删除线。Private Sub Command1_Click()Text1.FontSize = Text1.FontSize + 5End SubPrivate Sub
6、 Command2_Click()Text1.FontSize = Text1.FontSize - 5End SubPrivate Sub Command3_Click()Text1.FontBold = TrueEnd SubPrivate Sub Command4_Click()Text1.FontItalic = TrueEnd SubPrivate Sub Command5_Click()Text1.FontUnderline = TrueEnd SubPrivate Sub Command6_Click()Text1.FontStrikethru = True End Sub5.
7、设计一个窗体,如下图所示。程序中将 定义成符号常量(用 Const ),运行时,输入底面半径r 和圆柱高 h,然后单击“计算”命令按钮,在相应文本框中显示计算结果。运算结果为只读。Private Sub Command1_Click()Const pi = 3.14h = Val(Text1)r = Val(Text2)Text3.Text = pi * r 2Text4.Text = 2 * pi * r * hText5.Text = pi * r 2 * hEnd Sub36. 设计界面如上图所示。单击“出题”按钮,产生任意两个【1,100】之间的随机整数于 Text1、 Text2 中
8、,单击“计算”按钮,求两个数的和。运算结果为只读。Private Sub Command1_Click()Text1.Text = Int(100 * Rnd + 1)Text2.Text = Int(100 * Rnd + 1)End SubPrivate Sub Command2_Click()a = Val(Text1.Text)b = Val(Text1.Text)Text3.Text = a + bEnd Sub7设计一个数字钟表程序,界面如图所示。运行时单击窗体,显示当前的年月日星期及时间。Private Sub Form_Click()Label2.Caption = Year(
9、Now)Label4.Caption = Month(Now)Label6.Caption = Day(Now)Label9.Caption = Weekday(Now)Label11.Caption = TimeEnd Sub8设计一个数学函数程序,界面如图所示。程序运行时,在文本框中输入任意数值,单击相应按钮标签中显示结果。文本框始终处于选中状态。Private Sub Command1_Click()Label3.Caption = Abs(Val(Text1)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text
10、)End SubPrivate Sub Command2_Click()Label3.Caption = Sqr(Val(Text1)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text)End Sub4Private Sub Command3_Click()Label3.Caption = Fix(Val(Text1)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text)End SubPrivate Sub Command4_Click()L
11、abel3.Caption = Int(Val(Text1)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text)End SubPrivate Sub Command5_Click()Label3.Caption = Sgn(Val(Text1)Text1.SetFocusText1.SelStart = 0Text1.SelLength = Len(Text1.Text)End Sub9设计一工程,在文本框中输入一整数,单击“判断”按钮,判断能否同时被 3、5、7 整除,若能用 MsgBox 函数显示 “能同时被 3
12、、5、7 整除” ,否则显示“不能整除” 。Private Sub Command1_Click()a = Val(Text1)If a Mod 3 = 0 And a Mod 5 = 0 And a Mod 7 = 0 ThenMsgBox “能同时被 3、5、7 整除“ElseMsgBox “不能整除 “End IfEnd Sub10设计一个计算购书价钱的程序,界面如下图所示。为了提高运行速度,设置 Tab 键序,使得输入完单价后,焦点定位到输入数量文本框中。单击“计算总价”或用访问键,算出总价。总价文本框要求为只读属性。完成相应功能。Private Sub Command1_Click(
13、)a = Val(Text1)b = Val(Text2)Text3.Text = a * bEnd SubPrivate Sub Command2_Click()EndEnd Sub511设计一工程,界面如上图所示。程序运行,单击“计算” ,求出对应角度的三角函数的绝对值于文本框 Text2 中,同时要求选中文本框 Text1 内容,以便继续输入。Private Sub Command1_Click()a = Val(Text1)b = a * 3.14 / 180c = Abs(Sin(b)d = Abs(Cos(b)Text2.Text = Text2.Text String(a, “*
14、“)Next iEnd SubPrivate Sub Command2_Click()Clsa = Val(InputBox(“请输入行数 “)For i = 1 To aPrint Tab(a - i + 1); String(2 * i - 1, “*“)Next iEnd SubPrivate Sub Command3_Click()Clsa = Val(InputBox(“请输入行数 “)For i = a To 1 Step -1Print Tab(a - i + 1); String(2 * i - 1, “*“)Next iEnd SubPrivate Sub Command4_
15、Click()Clsa = Val(InputBox(“请输入行数 “)For i = a To 1 Step -1Print Tab(a - i + 1); String(2 * i - 1, “*“); _Space(3); String(2 * (a - i) + 1, “*“)Next iEnd Sub26设计如下图所示界面,单击时输出 N!和 1!+2!+N!结果,要求 N!用过程实现。Function h(n As Integer) As IntegerDim s As Integers = 1For i = 1 To ns = s * iNext ih = sEnd FunctionPrivate Sub Command1_Click()Dim n As Integern = Val(Text1)Text2.Text = h(n)End SubPrivate Sub Command2_Click()Dim n As Integerm = Val(Text1)