vba ms access 2010 中子窗体的相对大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19990988/
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
relative sizing of subforms in ms access 2010
提问by CodeMed
How do you set heights and widths of subforms to be percent of available screen real estate in ms access 2010? In particular, I have a nested navigation subform labeled "Tab A" in the database that I uploaded to this file sharing url: http://jmp.sh/v/HGctZ4Ru74vDAjzN43Wq
如何将子窗体的高度和宽度设置为 ms access 2010 中可用屏幕空间的百分比?特别是,我上传到此文件共享网址的数据库中有一个标记为“Tab A”的嵌套导航子表单:http: //jmp.sh/v/HGctZ4Ru74vDAjzN43Wq
In the database at the file sharing link, different users with different screen resolution settings have the navigation subform with Tab A showing up in all different sizes, including some where the subform is a ridiculously small percentage of the available screen real estate. The height of the detail section of the navigation subform is set to 5.5542 inches. Is there some way to set it so that the height is 90% of the space available below the top of the subform? I would also like for the width of the subform labeled "Tab 1" to be 90% of what is to the right of the left edge. In java, this is easy with offsets and calculated widths. I just cant seem to find instructions for how to do relative dimensions in access 2010.
在文件共享链接的数据库中,具有不同屏幕分辨率设置的不同用户具有带有 Tab A 的导航子窗体以各种不同的大小显示,包括一些子窗体在可用屏幕空间中所占的比例非常小。导航子窗体的详细信息部分的高度设置为 5.5542 英寸。有没有办法设置它,使高度是子窗体顶部下方可用空间的 90%?我还希望标记为“Tab 1”的子表单的宽度为左边缘右侧的宽度的 90%。在 java 中,这很容易使用偏移量和计算宽度。我似乎无法找到有关如何在 access 2010 中执行相对维度的说明。
Google searches on the topic don't seem to produce any solutions, and I want to avoid screwing up all the other users' screens by just adding an inch or two to the height setting.
谷歌对该主题的搜索似乎没有产生任何解决方案,我想避免通过在高度设置上增加一两英寸来避免搞砸所有其他用户的屏幕。
回答by HK1
In Access forms, all percentages or relative sizes are going to have to be calculated by you. I admit that sizing of forms and elements in Access is a little rigid and clumsy, but that's true of many desktop application GUI environments. I think .NET WPF has tried to fix this problem, but that has nothing to do with MS Access.
在 Access 表单中,您必须计算所有百分比或相对大小。我承认在 Access 中调整表单和元素的大小有点僵化和笨拙,但对于许多桌面应用程序 GUI 环境来说确实如此。我认为 .NET WPF 已尝试解决此问题,但这与 MS Access 无关。
I usually end up using something like this. This code belongs on the main form. That's where I always do my resizing.
我通常最终使用这样的东西。此代码属于主窗体。这就是我总是调整大小的地方。
Private Sub Form_Resize()
On Error Resume Next
Me.subform1.Width = Me.WindowWidth - 390
'or if you want to account for the form's left property
'Me.subform1.Width = Me.WindowWidth - (Me.subform1.Left + 100)
End Sub
Edit1:
编辑1:
In answer to your comment, 390 and 100 are twips. While design-time in Access does using inches, runtime properties must be set using twips.
在回答您的评论时,390 和 100 是缇。虽然 Access 中的设计时使用英寸,但必须使用缇设置运行时属性。
I messed with this for a bit and couldn't get anything I considered to be perfectly accurate. I'm posting the code below that makes the most logical sense to me, but then I don't know the ins and outs of how forms sizes are calculated in MS Access. It seems I'm probably missing something because the code below does not product accurate results. I found by increasing my Margins and decreasing the percentage/decimal for subform's height calculation I was able to get something that appeared relatively close but was unsatisfactory if you demand precise and exact numbers.
我弄乱了一点,无法得到任何我认为完全准确的东西。我在下面发布了对我来说最合乎逻辑的代码,但是我不知道在 MS Access 中如何计算表单大小的来龙去脉。似乎我可能遗漏了一些东西,因为下面的代码没有产生准确的结果。我发现通过增加我的边距和减少子表单高度计算的百分比/小数,我能够得到一些看起来相对接近但如果你需要精确和准确的数字并不令人满意的东西。
Private Sub Form_Resize()
On Error Resume Next
Const RMARGIN = 0
Const BMARGIN = 0
Me.subform1.Left = Round(Me.WindowWidth * 0.1) - RMARGIN
Me.subform1.Top = Round(Me.WindowHeight * 0.1) - BMARGIN
Me.subform1.Width = Round(Me.WindowWidth * 0.9) - (Me.subform1.Left + RMARGIN)
Me.subform1.Height = Round(Me.WindowHeight * 0.9) - (Me.subform1.Top + BMARGIN)
End Sub