上课笔记:
1.注意标题等文字不要写错
2.在控制某个控件功能的时候,要先找到控件的名字
3.combobox复选框添加一项,使用additem,这个函数的第一个参数表示添加什么文字,第二个参数表示添加到第几项,注意第二个参数从0开始表示
4.窗体加载事件form_load,这个事件中的代码在窗体显示出来之前运行
5.sub表示一个事件过程
6.private表示访问限制符,这里表示私有的(被form1窗体私有)
7.单选框option的value值为true表示选中,false表示不选中.option的backcolor属性表示背景色
8.文本框textbox的fontname表示字体名称、forecolor表示前景色(字体颜色)
9.checkbox复选框的value值为0表示未选中,1表示选中,2表示灰色选中效果
10.文本框textbox的fontItalic的true属性表示设置为斜体,false表示非斜体
11.使用not关键词就可以使得某个状态取反(往往用于布尔类型的数据boolean)
12.字体属性表示
FontBold表示是否加粗
FontUnderline表示是否有下划线
FontStrikethru表示是否有删除线
FontItalic表示是否为斜线
13.控件数组的相关事件中,如果有index就表示控件数组的index索引值,用来区分当前事件作用于哪个控件数组。
试题要求:
解题记录:
1.仔细读题,分析 ,创建工程
2.组合框中,如果选中了某个项目,那么就会将这个项目的文本显示到text属性中
3.文本框设置多行属性mutiline,设置滚动条属性scrollbar
4.窗体加载事件form_load
5.在combobox控件中插入某个位置的时候,注意第二个参数索引从0开始的。
6.设置字体FontName,设置前景色forecolor,设置斜体FontItalic
7.组合框中的项目单击事件使用click事件
8.使用一句话来完成一个状态相反的动作,使用not进行取反就可以了,例如斜体取反Text1.FontItalic = Not Text1.FontItalic
9.利用控件数组的索引选择的特性来一句话完成字体颜色设置的效果Text1.ForeColor = Option1(Index).BackColor
知识要点:
1.掌握字体颜色的综合控制forecolor
2.掌握字体的控制font相关的属性
3.掌握字形效果的控制font相关的属性,利用取反效果
4.掌握控件数组的基本使用
刘金玉编程,编程创造城市!
界面设计:
源代码分享:
Private Sub Check1_Click() Text1.FontBold = Not Text1.FontBold End Sub Private Sub Check2_Click() Text1.FontUnderline = Not Text1.FontUnderline End Sub Private Sub Check3_Click() Text1.FontStrikethru = Not Text1.FontStrikethru End Sub Private Sub Check4_Click() Text1.FontItalic = Not Text1.FontItalic End Sub Private Sub Combo1_Click() Text1.FontName = Combo1.Text End Sub Private Sub Form_Load() 'MsgBox "我是太难吃" Combo1.AddItem "华文宋体", 2 Option1(1).Value = True Text1.FontName = "楷体" Text1.ForeColor = Option1(1).BackColor Check4.Value = 1 Text1.FontItalic = True End Sub Private Sub Option1_Click(Index As Integer) Text1.ForeColor = Option1(Index).BackColor End Sub
相应的frm文件内界面详细配置
VERSION 5.00 Begin VB.Form Form1 Caption = "试题一" ClientHeight = 4080 ClientLeft = 120 ClientTop = 450 ClientWidth = 6465 LinkTopic = "Form1" ScaleHeight = 4080 ScaleWidth = 6465 StartUpPosition = 3 '窗口缺省 Begin VB.Frame Frame2 Appearance = 0 'Flat BackColor = &H00FFC0FF& Caption = "字体效果" ForeColor = &H80000008& Height = 1575 Left = 3360 TabIndex = 7 Top = 1680 Width = 2895 Begin VB.CheckBox Check4 Caption = "斜体" Height = 255 Left = 1320 TabIndex = 11 Top = 840 Width = 975 End Begin VB.CheckBox Check3 Caption = "删除线" Height = 255 Left = 120 TabIndex = 10 Top = 840 Width = 975 End Begin VB.CheckBox Check2 Caption = "下划线" Height = 255 Left = 1320 TabIndex = 9 Top = 360 Width = 975 End Begin VB.CheckBox Check1 Caption = "加粗" Height = 255 Left = 120 TabIndex = 8 Top = 360 Width = 975 End End Begin VB.Frame Frame1 Appearance = 0 'Flat BackColor = &H80000005& Caption = "字体颜色" ForeColor = &H80000008& Height = 1215 Left = 3360 TabIndex = 2 Top = 240 Width = 2895 Begin VB.OptionButton Option1 BackColor = &H00C00000& Caption = "颜色4" Height = 255 Index = 3 Left = 1200 TabIndex = 6 Top = 840 Width = 855 End Begin VB.OptionButton Option1 BackColor = &H00FFFF00& Caption = "颜色3" Height = 255 Index = 2 Left = 240 TabIndex = 5 Top = 840 Width = 855 End Begin VB.OptionButton Option1 BackColor = &H000080FF& Caption = "颜色2" Height = 255 Index = 1 Left = 1200 TabIndex = 4 Top = 360 Width = 855 End Begin VB.OptionButton Option1 BackColor = &H008080FF& Caption = "颜色1" Height = 255 Index = 0 Left = 240 TabIndex = 3 Top = 360 Width = 855 End End Begin VB.TextBox Text1 Height = 3015 Left = 1800 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 1 Text = "test1.frx":0000 Top = 240 Width = 1335 End Begin VB.ComboBox Combo1 Height = 3060 ItemData = "test1.frx":000D Left = 240 List = "test1.frx":0020 Style = 1 'Simple Combo TabIndex = 0 Text = "楷体" Top = 240 Width = 1335 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Check1_Click() Text1.FontBold = Not Text1.FontBold End Sub Private Sub Check2_Click() Text1.FontUnderline = Not Text1.FontUnderline End Sub Private Sub Check3_Click() Text1.FontStrikethru = Not Text1.FontStrikethru End Sub Private Sub Check4_Click() Text1.FontItalic = Not Text1.FontItalic End Sub Private Sub Combo1_Click() Text1.FontName = Combo1.Text End Sub Private Sub Form_Load() 'MsgBox "我是太难吃" Combo1.AddItem "华文宋体", 2 Option1(1).Value = True Text1.FontName = "楷体" Text1.ForeColor = Option1(1).BackColor Check4.Value = 1 Text1.FontItalic = True End Sub Private Sub Option1_Click(Index As Integer) Text1.ForeColor = Option1(Index).BackColor End Sub