简体   繁体   English

使用Z顺序和位置来组织MS Access中的打开表单

[英]Use Z-order and position to organize open forms in MS Access

For MS Access 2010, I need a way to flexibly maintain the position and Z-order when a dozen forms are open. 对于MS Access 2010,我需要一种方法,在打开十几个表单时灵活地保持位置和Z顺序。 There can be multiple instances of the Parent form, and each one can lead to multiple instances of the Child form (some background here ). 父表单可以有多个实例,每个实例都可以导致子表单的多个实例( 这里有一些背景 )。

I want the user to be able to choose which form is top-most -- which means I don't want any forms set as Popup . 我希望用户能够选择哪个表单是最顶层的 - 这意味着我不希望任何表单设置为Popup Also, I want the Z-Order essentially preserved when a new Child opens. 此外,我希望在新的Child打开时基本上保留Z-Order。 As the Child opens, the Parent loses the focus; 随着孩子的开放,父母失去了焦点; at that point I'd like the Parent to drop back to its former position in the Z-order. 在那一点上,我希望家长能够回到原来的Z顺序。 I could add requirements along this line, but you get the idea ... I imagined a default behavior might do what I want, but if I have to assign Z-order locations from an array or something like that, I could accept that. 我可以在这一行添加需求,但你明白了......我想象一个默认行为可能会做我想要的,但如果我必须从数组或类似的东西分配Z顺序位置,我可以接受。

I also want to control the on-screen position of the Child forms (I mean only when they are first opened; they can be repositioned). 我还想控制子窗体的屏幕位置(我的意思是只有在它们第一次打开时才可以重新定位)。 If they open with the same X,Y coordinates, they'll appear stacked on top of each other and the user will have to reposition the top instance in order to see the others. 如果它们以相同的X,Y坐标打开,它们将显示为堆叠在彼此之上,并且用户将必须重新定位顶部实例以便查看其他实例。 That is inconvenient and, more important I think, disorienting. 这是不方便的,更重要的是我认为,迷失方向。

So far I'm not able to have it all. 到目前为止,我无法拥有这一切。 I can get a nice cascade result by specifying X,Y positions, but it stops working when I use the flags to poke at the Z-order. 通过指定X,Y位置,我可以得到一个很好的级联结果,但是当我使用标志在Z顺序戳时它会停止工作。

I've been using the API... 我一直在使用API​​ ......

Declare Sub SetWindowPos Lib "user32" ( _
                ByVal Hwnd&, _
                ByVal hWndInsertAfter&, _
                ByVal X&, ByVal Y&, ByVal cX&, _
                ByVal cY&, ByVal wFlags&)

Global Const HWND_TOP = 0
Global Const HWND_TOPMOST = -1

SetWindowPos Hwnd, HWND_TOP, lngPosX, lngPosX, 0, 0, SWP_NOSIZE

I have different results when I try options for hWndInsertAfter& and wFlags& . 当我尝试hWndInsertAfter&wFlags&选项时,我有不同的结果。 Also when I set forms as Popup (results are better, but as mentioned, I want the user to bring any form to the top; therefore no Popup ). 此外,当我将表单设置为Popup (结果更好,但如上所述,我希望用户将任何表单带到顶部;因此没有Popup )。

(Hmm... I bet Popup (and 'Modal`) are precisely what bring the API into best usage, because while a "must-answer" dialog is showing, control basically reverts to Windows. Confirm?) (嗯......我敢打赌Popup (以及'Modal`)正是将API用于最佳用途的原因,因为当显示“必须回答”对话框时,控件基本上还原为Windows。确认?)

My biggest frustration is that documentation for the API seems fragmentary and incoherent. 我最大的挫败感是API的文档似乎是零碎和不连贯的。 And I wonder, am I stuck with that API? 我想知道, 我是否坚持使用该API? Is there something else I can use? 还有其他我可以使用的东西吗? I'd love a VBA solution apart from the API, but I guess this is what the API is for. 我喜欢除了API之外的VBA解决方案,但我想这就是API的用途。 Still, is there a method I'm missing? 不过,有没有一种方法我不见了?

I can post my variant attempts in more detail, but I feel I've been shooting in the dark, so I will wait on your feedback. 我可以更详细地发布我的变种尝试,但我觉得我一直在黑暗中拍摄,所以我会等你的反馈。

Update 更新

I tried Reading The Manual . 我试过阅读手册 I tried twiddling with "form ownership" and NO/TOPMOST . 我尝试了“形式所有权”和NO/TOPMOST For the Child form, I still have to choose between: 对于儿童表格, 我仍然需要选择:

  1. Being able to set the position upon opening 能够在开场时设定位置
  2. Being able to bring the Parent form back "on top" of the Child 能够将“父母”表格带回“儿童”的“顶部”

Sorry for the late answer! 抱歉回复晚了! I bumped into this while searching for a related issue. 我在搜索相关问题时遇到了这个问题。

One way to manage Z-order 'Access-only' is to use Form.SetFocus. 管理Z-order'Access-only'的一种方法是使用Form.SetFocus。 The general solution outline: 一般解决方案大纲:

  1. Keep an array or collection of your form names and their Z-orders 保留表单名称及其Z顺序的数组或集合
  2. When Z-order changes: 当Z顺序改变时:
  3. Resort your list to reflect the new Z-order 选择您的清单以反映新的Z订单
  4. Turn screen updating off: Application.Echo False 关闭屏幕更新:Application.Echo False
  5. Iterate through your list of forms in reverse Z-order. 以反向Z顺序遍历表单列表。 Use Form.SetFocus for each form. 对每个表单使用Form.SetFocus。 This will put the highest form on top. 这将把最高形式放在首位。
  6. Turn screen updating back on: Application.Echo True 重新打开屏幕更新:Application.Echo True

This should work as long as all of your forms are non-modal. 只要您的所有表单都是非模态的,这应该可以正常工作。

If you need modal forms, be aware that they are by default on top, and you can only have one modal form open at a time. 如果您需要模态表单,请注意它们默认位于顶部,并且您一次只能打开一个模式表单。 You can still use the above logic, just be sure to set Form.Modal = False for every form not on the top. 您仍然可以使用上述逻辑,只需确保为不在顶部的每个表单设置Form.Modal = False。

This is the 'how' answer, but I can't offer advice as to whether this is a sound approach for your application. 这是“如何”的答案,但我不能就这是否适合您的应用提供建议。

I believe the solution doesn't exist, or isn't worth pursuing because it would lean on Windows API libraries that may not be available in a few years. 我认为该解决方案不存在,或者不值得追求,因为它将依赖于几年内可能无法使用的Windows API库。 (This pessimism is not based on specific insights; but in general I see big pressures on the Windows user interface, so it's easy to imagine things shifting.) (这种悲观主义并非基于特定的见解;但总的来说,我看到Windows用户界面面临巨大压力,所以很容易想象事情会发生变化。)

I see some other hazards. 我看到其他一些危险。 Users will open numerous windows; 用户将打开许多窗口; resources will fail at some point, and probably before then they'll have lost any advantages from a human analytical point of view. 资源在某些时候会失败,可能在此之前,他们将从人类分析的角度失去任何优势。 Nonetheless they'll continue past the point of diminishing returns. 尽管如此,他们还是会继续超越收益递减的程度。 Also I can expect to find a few pitfalls that gobble development time and lead in the end to complaints no matter how much time I spend mitigating them. 此外,我可以期待找到一些陷阱,吞噬开发时间并最终导致投诉,无论我花多少时间来减轻它们。 Think "multi-user" and you'll know what I mean. 想想“多用户”,你会明白我的意思。

Instead, I need to re-think the approach. 相反,我需要重新思考这种方法。 The application offers complicated and sometimes volumnous information. 该应用程序提供复杂的,有时很多的信息。 There's a way to do it. 有办法做到这一点。 Not this way. 不是这样的。

I might delete this OP, but it's gotten three up-votes, so I'll wait and see what you think. 我可能会删除这个OP,但是它已经获得了三次投票,所以我会等着看你的想法。 I can always punt to community wiki. 我总是可以向社区wiki倾斜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM