vba 在 Access 中制作自定义切换按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26805052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making custom toggle buttons in Access
提问by Alex
Is there any way to make a custom toggle button in Access? I'm looking to create an on/off switch. The built in toggle button is fugly.
有没有办法在 Access 中制作自定义切换按钮?我正在寻找创建一个开/关开关。内置的切换按钮很丑。
I have already created the on/off/hover images in photoshop. Is there a way to import them code them to work like the built in toggle button?
我已经在 photoshop 中创建了开/关/悬停图像。有没有办法导入它们,让它们像内置的切换按钮一样工作?
采纳答案by Fionnuala
It should be easy enough to simply adjust the picture property, for example:
简单地调整图片属性应该很容易,例如:
Private Sub Toggle0_Click()
If Me.Toggle0 Then
Me.Toggle0.Picture = "Z:\Docs\Picture1.bmp"
Else
Me.Toggle0.Picture = "Z:\Docs\Picture2.bmp"
End If
End Sub
回答by Albert D. Kallal
Access 2010 has an AMAZING button editor, and the combinations and glow and shadow effects are amazing. In less time to type this sentence, I made these toggle buttons:
Access 2010 有一个令人惊叹的按钮编辑器,其组合以及发光和阴影效果令人惊叹。在更短的时间内输入这句话,我制作了这些切换按钮:
In above the button differences is when the button is depressed or not (so dark blue examples above are those that are depressed)
上面按钮的区别在于按钮是否被按下(所以上面深蓝色的例子是那些被按下的)
Here is a screen cap of the built in tools in Access used to create the above – I did not use any 3rd party tools to build the above. As pointed out by others here you can include an image with the button.
这是用于创建上述内容的 Access 中内置工具的屏幕截图——我没有使用任何 3rd 方工具来构建上述内容。正如其他人在此处指出的那样,您可以在按钮中包含图像。
回答by Lord Peter
Just one possible way (I'm sure there are many):-
只有一种可能的方式(我确定有很多):-
Put both your images into image controls on the form, and line them up on top of each other. In the click event of each control, use something like this:-
将您的两个图像放入表单上的图像控件中,并将它们排成一行。在每个控件的点击事件中,使用如下内容:-
Private Sub img1_Click()
Me.img2.Visible = True
Me.img1.Visible = False
End Sub
Private Sub img2_Click()
Me.img1.Visible = True
Me.img2.Visible = False
End Sub
Where img1 and img2 are your "on" and "off" image controls. You can set one of them visible in the load event of your form, and you can tell what the status of your "switch" is, by inspecting the visible property of the controls.
其中 img1 和 img2 是您的“开”和“关”图像控件。您可以将其中一个设置在表单的加载事件中可见,并且您可以通过检查控件的可见属性来判断“开关”的状态。