他山之石——VBA选项按钮、复选框、框架、滚动条、微调、图像与多页
他山之石——VBA选项按钮、复选框、框架、滚动条、微调、图像与多页_预见未来to50的专栏-CSDN博客_vba 选项按钮
麻雀虽小,五脏俱全。用VBA制作软件原型应该也不错,有机会可以尝试一下。
'************单选和复选框*************
Private Sub CommandButton1_Click()
Dim sr As String
If CheckBox1.Value = True Then sr = sr & " " & CheckBox1.Caption
If CheckBox2.Value = True Then sr = sr & " " & CheckBox2.Caption
If CheckBox3.Value = True Then sr = sr & " " & CheckBox3.Caption
TextBox3.Value = sr
End Sub
Private Sub OptionButton3_Click()
If Me.男.Value = True Then
TextBox3.Value = "男"
End If
End Sub
Private Sub OptionButton4_Click()
If Me.女.Value = True Then
TextBox3.Value = "女"
End If
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub Image1_Click()
End Sub
'**********滚动条与*微调按钮****************
'一 常用方法和属性
'1 设置最大值和最小值
'Max属性
'min属性
'2 步长(每点击两边按钮和滑块增加或减少的步长)
'largechange属性,只用于滚动条,点击一次中间增加或减少的数
'smallchange属性,点击一次按变化的数
二 事件
Private Sub ScrollBar1_Change()
TextBox1.Value = ScrollBar1.Value
End Sub
Private Sub SpinButton1_Change()
'TextBox1.Value = ScrollBar1.Value
End Sub
Private Sub SpinButton1_SpinUp()
TextBox2 = DateAdd("d", -1, TextBox2.Value)
End Sub
Private Sub SpinButton1_SpinDown()
TextBox2 = DateAdd("d", 1, TextBox2.Value)
End Sub
Private Sub UserForm_Initialize()
Dim f As String
f = Dir(ThisWorkbook.path & "\pic\*.jpg")
Do
Me.ListBox1.AddItem f
f = Dir
Loop Until Len(f) = 0
TextBox2 = Date
End Sub
'**********图片控件****************
'图片控件中图片的导入
Private Sub ListBox1_Click()
Dim path
path = ThisWorkbook.path & "/pic/" & ListBox1.Value
Image1.Picture = LoadPicture(path) '用loadpicture函数加载图片
End Sub
'**********多页控件****************
'1 多页控件的多行是指什么?
'MultiRow 属性:当多页控件的标签很多时,可以分多行显示。
'2 多页控件的值
'1 选择第1个标签,Value为0,选择第2个Value为1....选择第N个Value为N-1
'2 设置值的属性后可以直接选取这个标签。如MultiPage1.Value=0 就可以选取第2个标签
Private Sub MultiPage1_Change()
' MsgBox MultiPage1.Value
End Sub
'3 隐藏标签
'Style 属性值为2时,可以隐藏标签
' Me.MultiPage1.Style = 2
Private Sub UserForm_Initialize()
Me.MultiPage1.Style = 2
Me.MultiPage1.Value = 0
按钮权限
End Sub
Sub 按钮权限()
Select Case Me.MultiPage1.Value
Case 0
上一步.Enabled = False
Me.Caption = "第1步 共" & Me.MultiPage1.Pages.Count & "步"
Case Me.MultiPage1.Pages.Count - 1
下一步.Enabled = False
Me.Caption = "第" & MultiPage1.Pages.Count & "步 共" & Me.MultiPage1.Pages.Count & "步"
Case Else
上一步.Enabled = True
下一步.Enabled = True
Me.Caption = "第" & MultiPage1.Value + 1 & "步 共" & Me.MultiPage1.Pages.Count & "步"
End Select
End Sub
Private Sub 上一步_Click()
Me.MultiPage1.Value = Me.MultiPage1.Value - 1
按钮权限
End Sub
Private Sub 下一步_Click()
Me.MultiPage1.Value = Me.MultiPage1.Value + 1
按钮权限
End Sub
————————————————
版权声明:本文为CSDN博主「预见未来to50」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hpdlzu80100/article/details/80888314
赞 (0)