VB程序学习代码记录20160723

这篇博客详细记录了VB编程的学习过程,包括文本实例、列表操作的实战、使用组合框和滚动条的技巧,特别提到了一个滚动条实例的应用,还介绍了打砖块游戏的实现以及控件数组和调色板的运用。
摘要由CSDN通过智能技术生成

文本实例

Private Sub Command1_Click()
    For i = 0 To 2
        If Option1(i).Value = True Then
            Text1.FontName = Option1(i).Caption
        End If
    Next i
    If Option4(0).Value = True Then Text1.ForeColor = vbRed
    If Option4(1).Value = True Then Text1.ForeColor = vbYellow
    If Option4(2).Value = True Then Text1.ForeColor = vbBlue
    For i = 0 To 2
        If Option7(i).Value = True Then
            Text1.FontSize = Val(Option7(i).Caption)
        End If
    Next i
    Text1.FontBold = Check1.Value
    Text1.FontItalic = Check2.Value
    Text1.FontUnderline = Check3.Value
    Text1.FontStrikethru = Check4.Value
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

列表操作1

Private Sub Command1_Click()
    Dim x As String
    x = InputBox("请输入城市名称", , 0)
    List1.AddItem x
    Label3.Caption = "新添加的项目为" & List1.List(List1.ListCount - 1)
    Label1.Caption = "列表中项目数为:" & List1.ListCount & "个"
End Sub

Private Sub Form_Load()
    Command1.Caption = "添加城市"
    Label1.Caption = "列表中项目数为:" & List1.ListCount & "个"
End Sub

Private Sub List1_Click()
    Label2.Caption = "您选择的城市为:" & List1.List(List1.ListIndex)
End Sub

列表操作2

Dim i As Integer
Private Sub Command1_Click()
    If List1.ListIndex = -1 Then
        MsgBox "请选择项目"
        Exit Sub
    End If
    For i = 1 To 20
        If List1.List(List1.ListIndex) = List2.List(i) Then
            MsgBox "该项目已添加"
            Exit Sub
        End If
    Next i
    List2.AddItem List1.ListIndex
End Sub

Private Sub Command2_Click()
    If List2.ListIndex = -1 Then
        MsgBox "请选择要移除的项目"
        Exit Sub
    End If
    List2.RemoveItem Index
End Sub

Private Sub Command3_Click()
    If MsgBox("确定清空?", 4) = vbYes Then List2.Clear
End Sub

Private Sub Command4_Click()
    List1.AddItem "Item" & i
    i = i + 1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值