机房收费系统优化篇

一、给主窗体添加快捷键:

1、将cmdok的default的属性设为true
2、在主窗体中添加如下代码:

Private Sub form_KeyPress(KeyAscii As Integer)
         If KeyAscii = 13 Then
        Me.Hide
        frmMain.Show
    End If
End Sub

二、字符的限制

文本框的限制:

Private Sub txtUserName_keypress(KeyAscii As Integer)
 Dim ctemp As String
    ctemp = "#$%^&*"   '禁止输入的字符
    If InStr(1, ctemp, Chr(KeyAscii)) <> 0 Then
        KeyAscii = 0
    End If
Select Case KeyAscii
    Case 48 To 57 '只能输入数字
    Case 65 To 90 '只能输入大小写字母
    Case 97 To 122 ' 只能输入退格
    Case 8
    Case Else
    KeyAscii = 0
End Select

End Sub

三、如何让combo框不能输入字符

在combo框的keypress事件中输入keyascii=0

四、如何调整mshflexgrid控件的单元格的大小,使得让他们可以根据字符串的大小来进行调整

第一步:在模块中添加以下代码:

    '声明函数自动调整mshflexgrid控件的单元格的大小
    Public Sub AdjustColWidth(frmCur As Form, gridCur As Object, Optional bNullRow As Boolean = True, Optional dblIncWidth As Double = 0)
    '--------------------------------------------------------------------
    '功能:
    '       自动调整Grid各列列宽为最合适的宽度
    '参数:
    '       [frmCur].........................................当前工作窗体
    '       [gridCur]........................................当前要调整的Grid
    '--------------------------------------------------------------------
    Dim i, j As Integer
    Dim dblWidth As Double
        With gridCur
            For i = 0 To .Cols - 1
                dblWidth = 0
                If .ColWidth(i) <> 0 Then
                    For j = 0 To .Rows - 1
                        If frmCur.TextWidth(.TextMatrix(j, i)) > dblWidth Then
                            dblWidth = frmCur.TextWidth(.TextMatrix(j, i))
                        End If
                    Next
                    .ColWidth(i) = dblWidth + dblIncWidth + 800
                End If
            Next
        End With

End Sub

第二步:在各个子窗体中调用:

Call AdjustColWidth(窗体名字,控件名字)

小技巧篇:

如何一键删除所有控件中所有的内容
代码如下:

Private Sub cmdclear_Click()
    Dim ctrl As Control
 
    For Each ctrl In Me.Controls
            Rem:如果控件的类型为combo
            If TypeOf ctrl Is ComboBox Then
                    ctrl.Text = ""
            End If
 
            Rem:如果控件的类型是text
            If TypeOf ctrl Is TextBox Then
                    ctrl.Text = ""
            End If
 
            Rem:如果控件的类型是msflexgrid
            If TypeOf ctrl Is msflexgrid Then
                    ctrl.Clear
            End If
    Next
    
End Sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值