Private Sub ToggleButton3_Click()If ToggleButton3.Value = True ThenRange("d50").Value = 1Worksheets(2).Select
ElseRange("d50").Value = 0Worksheets(3).Select
End IfEnd SubPrivate Sub ToggleButton4_Click()
ToggleButton3.Value = ToggleButton4.Value
End Sub
Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標按下"
Debug.Print "鼠標按下"
Debug.Print Button
Debug.Print Shift '可以傳遞參數(shù),判斷是否按下了SHIFT
Debug.Print X
Debug.Print Y'只有鼠標按下不動的那個持續(xù)的狀態(tài)才算,一松開就不算了
End SubPrivate Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標滑過"
'感覺優(yōu)先級高于 mouseup
Debug.Print "鼠標滑過"
End SubPrivate Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標松開"
'基本是個常態(tài),鼠標一松馬上顯示 鼠標松開,一直處于 鼠標松開狀態(tài)
Debug.Print "鼠標松開"End Sub
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
CommandButton1.Caption = "KEY按下了"
Debug.Print Shift
'實測是任何鍵按下了都算End SubPrivate Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CommandButton1.Caption = "KEY點擊了"
Debug.Print Shift
'點擊鍵盤按鍵才觸發(fā)
'有可能keydown 但不觸發(fā) keyPress嗎?好像不能,keydown 幾乎等于keypress吧
'優(yōu)先級總是高于 keydown
End SubPrivate Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
CommandButton1.Caption = "KEY松開了"
Debug.Print Shift
'實測是任何鍵按下了以后,再松開都算
End Sub
Private Sub CommandButton1_Click()
CommandButton1.Caption = "點擊" & a & "次"
a = a + 1
'按下和起來是2個狀態(tài),要么是按下,要么是起來Debug.Print CommandButton1.Value '沒有值默認為false?還是有切換?End Sub
Private Sub CommandButton1_BeforeDragOver(ByVal Cancel As MSForms.ReturnBoolean, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal DragState As MSForms.fmDragState, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
CommandButton1.Caption = "BeforeDragOver"
Debug.Print "BeforeDragOver"
'???
End SubPrivate Sub CommandButton1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
CommandButton1.Caption = "BeforeDropOrPaste"
Debug.Print "BeforeDropOrPaste"
'???
End SubPrivate Sub CommandButton1_Click()
CommandButton1.Caption = "已經(jīng)按下"
'按下和起來是2個狀態(tài),要么是按下,要么是起來
End SubPrivate Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CommandButton1.Caption = "你想弄啥"
'操作很明確
End SubPrivate Sub CommandButton1_Error(ByVal Number As Integer, ByVal Description As MSForms.ReturnString, ByVal SCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, ByVal CancelDisplay As MSForms.ReturnBoolean)
Debug.Print "按鈕還會報錯?"
'???
End SubPrivate Sub CommandButton1_GotFocus()
CommandButton1.Caption = "來點我啊"
'測試了下,獲得焦點的時觸發(fā)get,點了其他單元格或?qū)ο蟛艜|發(fā)lostfocus
'和鼠標軌跡無關,移到上面并不觸發(fā),移走也不觸發(fā)lostfocus
End SubPrivate Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
CommandButton1.Caption = "按下了"
End SubPrivate Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CommandButton1.Caption = "點擊了"
'點擊鍵盤按鍵才觸發(fā)
End SubPrivate Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'???
End SubPrivate Sub CommandButton1_LostFocus()
CommandButton1.Caption = "離開了"
'測試需要真正的焦點變化到其他地方才算,鼠標挪開不算
End SubPrivate Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標按下"
'測試了,只有鼠標按下不動的那個持續(xù)的狀態(tài)才算,一松開就不算了
End SubPrivate Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標滑過"
End SubPrivate Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠標松開"
'沒試驗出來?
'???
End Sub
?
3.2.6 CommandButton的各種屬性和方法?
?commandbutton.value=false ?
?
4? 第3類:option ,checkbox ,分組框
4.1 option 和分組框
好像放在附近的多個option,會自動識別為一組?不寫代碼也行?
暫時只知道寫這樣簡單的代碼
實現(xiàn)互斥效果
實現(xiàn)取得option按鈕的返回值的
Private Sub OptionButton1_Click()
OptionButton2.Value = False
a = OptionButton1.Value
Debug.Print aEnd SubPrivate Sub OptionButton2_Click()
OptionButton1.Value = False
a = OptionButton2.Value
Debug.Print aEnd Sub
?
4.2? CheckBox
checkbox 感覺每個都是獨立的,代碼只需要取的每個 checkbox的返回值就可以?
可以設置其顏色?CheckBox2.BackColor = RGB(255, 0, 0)
Private Sub CheckBox1_Click()
a = CheckBox1.Value '作用是不是就是這個checkbox返回其勾選值?
Debug.Print a
End SubPrivate Sub CheckBox2_Click()
a = CheckBox2.Value
Debug.Print aCheckBox2.BackColor = RGB(255, 0, 0)
'CheckBox2.Border = normal
Debug.Print CheckBox2.Name
'Debug.Print CheckBox2.ParentEnd Sub