第10章習(xí)題
一、單選題
C 2. (1)A (2)C 3.D
4.C 5. A 6. D
7. (1)A (2)D 8. A
9. B 10. B 11. A
12. D
二、填空題
(1)Change
(2)Value
(3)Scroll
(4)Value
2.
(1) P1.Picture
(2) P2.Picture
(3) P2.Picture = P3.Picture
3. 菜單編輯器,頂;PopUpMenu
4.
(1) Button.Index
(2) BackColor = RGB(255, 0, 0)
(3) BackColor = RGB(0, 255, 0)
(4) BackColor = RGB(0, 0, 255)
5.
(1) Picture1
(2) "X=" + Str(X)
(3) "Y=" + Str(Y)
6. DragMode, 1; 0
7. Action, 4, ShowFont
編程及上機(jī)調(diào)試
1.在窗體上建立一個(gè)水平滾動(dòng)條HScroll1和一個(gè)文本框Text1。程序代碼如下:
Private Sub Form_Load()
HScroll1.Max = 1000
HScroll1.Min = 0
HScroll1.LargeChange = 5
HScroll1.LargeChange = 10
HScroll1.Value = 500
End Sub
Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
End Sub
Private Sub HScroll1_Scroll()
Text1.Text = HScroll1.Value
End Sub
2. 在窗體上建立一個(gè)計(jì)時(shí)器Timer1和“開始”、“停止”兩個(gè)命令按鈕。程序代碼如下:
Private len_S As Single, s As Integer '模塊級變量
Private Sub Command1_Click() '“開始”
Timer1.Enabled = True
s = 0
Call Sub_Move
End Sub
Private Sub Command2_Click() '“停止”
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
'先取各指針的長度
len_S = Sqr((LineS.Y2 - LineS.Y1) ^ 2 + (LineS.X2 - LineS.X1) ^ 2) '秒針長度
End Sub
Private Sub Timer1_Timer() '定時(shí)器的定時(shí)事件過程
s = s + 1
Call Sub_Move
End Sub
Private Sub Sub_Move() '定時(shí)器的定時(shí)事件過程
pi = 3.14159
LineS.X2 = LineS.X1 + len_S * Sin(pi * s / 30) '繪制秒針
LineS.Y2 = LineS.Y1 - len_S * Cos(pi * s / 30)
End Sub
3. 按要求在窗體上設(shè)計(jì)一個(gè)二級下拉菜單。
4. 在窗體上建立一個(gè)通用對話框CommonDialog1、“打開”及“字體”兩個(gè)命令按鈕和文本框Text1。程序代碼如下:
Private Sub Command1_Click() '"打開"
CommonDialog1.DialogTitle = "選擇文件"
CommonDialog1.Filter = "文本文件|*.txt" '設(shè)置文件過濾器
CommonDialog1.InitDir = "C:\" '設(shè)置默認(rèn)文件夾
CommonDialog1.ShowOpen '顯示“打開”對話框
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click() '"字體"
CommonDialog1.Flags = cdlCFScreenFonts
CommonDialog1.ShowFont
Text1.FontName = CommonDialog1.FontName '設(shè)置字體名稱
Text1.FontSize = CommonDialog1.FontSize '設(shè)置字體大小
Text1.FontBold = CommonDialog1.FontBold '粗體
Text1.FontItalic = CommonDialog1.FontItalic '斜體
End Sub