Private Sub Label1_Click()
Label1.BackColor = &O555555
End Sub
Private Sub TextBox1_Change()
Debug.Print TextBox1.Value
Debug.Print TextBox1
TextBox1.BackColor = RGB(0, 255, 0)
End Sub
Private Sub ToggleButton1_Click()
ToggleButton1.Caption = "男"
ToggleButton2.Value = False
'ToggleButton1.TripleState = False
'ToggleButton2.TripleState = False
If ToggleButton1.Value = True Then
Debug.Print "toggle1按下了"
Range("M39").Value = "toggle1按下了"
Else
Debug.Print "toggle1弹起了"
Range("M39").Value = "toggle1弹起了"
End If
Debug.Print "toggle1被click执行1次"
End Sub
Private Sub ToggleButton2_Click()
ToggleButton2.Caption = "女"
ToggleButton1 = False 'ToggleButton1.value = False
'ToggleButton2.TripleState = False
'ToggleButton1.TripleState = False
If ToggleButton2.Value = True Then
Debug.Print "toggle2按下了"
Range("M43").Value = "toggle2按下了"
Else
Debug.Print "toggle2弹起了"
Range("M43").Value = "toggle2弹起了"
End If
Debug.Print "toggle2被click执行1次"
End Sub
Private Sub ToggleButton3_Click()
If ToggleButton3.Value = True Then
Range("d50").Value = 1
Worksheets(2).Select
Else
Range("d50").Value = 0
Worksheets(3).Select
End If
End Sub
Private 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 '可以传递参数,判断是否按下了SHIFT
Debug.Print X
Debug.Print Y
'只有鼠标按下不动的那个持续的状态才算,一松开就不算了
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠标滑过"
'感觉优先级高于 mouseup
Debug.Print "鼠标滑过"
End Sub
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠标松开"
'基本是个常态,鼠标一松马上显示 鼠标松开,一直处于 鼠标松开状态
Debug.Print "鼠标松开"
End Sub
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
CommandButton1.Caption = "KEY按下了"
Debug.Print Shift
'实测是任何键按下了都算
End Sub
Private Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CommandButton1.Caption = "KEY点击了"
Debug.Print Shift
'点击键盘按键才触发
'有可能keydown 但不触发 keyPress吗?好像不能,keydown 几乎等于keypress吧
'优先级总是高于 keydown
End Sub
Private 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个状态,要么是按下,要么是起来
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 Sub
Private 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 Sub
Private Sub CommandButton1_Click()
CommandButton1.Caption = "已经按下"
'按下和起来是2个状态,要么是按下,要么是起来
End Sub
Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CommandButton1.Caption = "你想弄啥"
'操作很明确
End Sub
Private 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 Sub
Private Sub CommandButton1_GotFocus()
CommandButton1.Caption = "来点我啊"
'测试了下,获得焦点的时触发get,点了其他单元格或对象才会触发lostfocus
'和鼠标轨迹无关,移到上面并不触发,移走也不触发lostfocus
End Sub
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
CommandButton1.Caption = "按下了"
End Sub
Private Sub CommandButton1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
CommandButton1.Caption = "点击了"
'点击键盘按键才触发
End Sub
Private Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'???
End Sub
Private Sub CommandButton1_LostFocus()
CommandButton1.Caption = "离开了"
'测试需要真正的焦点变化到其他地方才算,鼠标挪开不算
End Sub
Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠标按下"
'测试了,只有鼠标按下不动的那个持续的状态才算,一松开就不算了
End Sub
Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠标滑过"
End Sub
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
CommandButton1.Caption = "鼠标松开"
'没试验出来?
'???
End Sub
Private Sub OptionButton1_Click()
OptionButton2.Value = False
a = OptionButton1.Value
Debug.Print a
End Sub
Private Sub OptionButton2_Click()
OptionButton1.Value = False
a = OptionButton2.Value
Debug.Print a
End Sub
Private Sub CheckBox1_Click()
a = CheckBox1.Value '作用是不是就是这个checkbox返回其勾选值?
Debug.Print a
End Sub
Private Sub CheckBox2_Click()
a = CheckBox2.Value
Debug.Print a
CheckBox2.BackColor = RGB(255, 0, 0)
'CheckBox2.Border = normal
Debug.Print CheckBox2.Name
'Debug.Print CheckBox2.Parent
End Sub
Private Sub ListBox1_Click()
'arr1 = Array(11, 22, 33, 44, 55)
'ListBox1.Value = arr1
'好像只能additem 不能数组赋值,感觉像字典?
ListBox1.AddItem 1
ListBox1.AddItem 2
ListBox1.AddItem 3
ListBox1.AddItem 4
ListBox1.AddItem 5
Debug.Print ListBox1.Value
Debug.Print ListBox1.Text
End Sub
Private Sub ComboBox1_Change()
ComboBox1.AddItem 10
ComboBox1.AddItem 20
ComboBox1.AddItem 30
ComboBox1.AddItem 40
ComboBox1.AddItem 50
Debug.Print ComboBox1.Value
ComboBox1.BackColor = RGB(255, 0, 0)
End Sub
Private Sub SpinButton1_Change()
Debug.Print SpinButton1.Value;
Debug.Print SpinButton1.Index '看起来这个像是控件的序号ID
'测试了下,如果不设置值域范围,好像最小是0,最大好像正整数都可以?
'设置值域范围,但是没有外部反应
SpinButton1.Min = 1
SpinButton1.Max = 15
SpinButton1.SmallChange = 3
End Sub
1
Private Sub UserForm_Initialize()
ScrollBar1.Value = 1
End Sub