一、密碼框不可輸入空格
1.首先先去數據庫將user PWD列的數據類型改爲varchar(20),這樣做的目的是將密碼的後面的空格去掉。假如說不改數據類型,用戶名與密碼都是9的情況下,登錄的時候“9+空格” 也可以登陸成功。
2.限制字符(字數、空格。我的理解密碼可以是特殊字符,可以增強安全性。)
Private Sub txtPassword2_KeyPress(KeyAscii As Integer)
'限制字數
If Len(txtPassword2.Text) > 10 Then
KeyAscii = 0
MsgBox "字數超出 ", 64, "溫馨提示:"
txtPassword2.Text = ""
End If
'限制不可輸入空格
If KeyAscii = 32 Then
KeyAscii = 0
MsgBox "密碼不可爲空格 ", 64, "溫馨提示:"
txtPassword2.Text = ""
End If
End Sub
3.清空剪切板(當然也可以禁用右鍵,但是我總感覺得不償失)
Private Sub txtPassword1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 And KeyCode = vbKeyV Then '如果是Ctrl+V,清空剪貼板
Clipboard.Clear
End If
End Sub
Private Sub txtPassword1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then '如果是右鍵,清空剪貼板
Clipboard.Clear
End If
End Sub
二、查詢學籍信息添加提示框
這個小功能很簡單,添加一個Label就行。
當窗體加載的時候
Label1.Caption = "等待查詢"
當點擊查詢按鈕的時候
Label1.Caption = "查詢到" & mrc.RecordCount & "條記錄"
三、下拉框只能選擇不可輸入
我用的方法相當簡單,一句代碼即可:
Private Sub comOperator1_KeyPress(KeyAscii As Integer)
KeyAscii = 0
End Sub