简体   繁体   English

Libreoffice Base 宏 - 如何使表单上的控件可见/隐藏?

[英]Libreoffice Base macro - How to make visible/hide a control on a form?

I created a database Form with 2 comboboxes, Combo1 and Combo2 .我创建了一个包含 2 个组合框Combo1Combo2的数据库表单。 Combo2 visibility depends on Combo1 status: Combo1 checked, Combo2 visible; Combo2可见性取决于Combo1状态: Combo1选中, Combo2可见; Combo1 unchecked, Combo2 hidden. Combo1未选中, Combo2隐藏。

I expected to find something like Combo2.setVisible(Combo1.isVisible()) but I have been too optimist.我希望找到类似Combo2.setVisible(Combo1.isVisible())但我太乐观了。

This is the macro I have been playing with:这是我一直在玩的宏:

Sub MyMacro(oEvent as Object)
    msgbox(oEvent.Source.getState())   rem returns Checked/Unchecked status of Combo1
    msgbox(oEvent.source.model.Name)   rem Name of the Event generator (Combo1)
End Sub
cb2 = ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("Combo2")
msgbox(cb2.Name)

prints correctly Combo2 , so I assume I have a proper reference...正确打印Combo2 ,所以我假设我有一个正确的参考...

And now?现在?

Today is the very first day I play with Libreoffice Base (and its bugs), and this is just something nice that I would like to add for tomorrow's demo.今天是我使用 Libreoffice Base(及其错误)的第一天,这只是我想为明天的演示添加的好东西。 I NEVER used before a macro both in Microsoft nor Libreoffice suites, so I am moving veeery slow.我从来没有在 Microsoft 和 Libreoffice 套件中使用过宏,所以我的移动速度非常慢。

Last time I used BASIC was probably around 1990.我上次使用 BASIC 大概是在 1990 年左右。

I went through a number of tutorials online (usually based on Libreoffice Calc cells), string-searched both main books by Andrew Pitonyak ("Useful Macro Information For OpenOffice.org" and "OpenOffice.org Macros Explained (OOME)") but after trying tons of snippets I got nowhere.我浏览了许多在线教程(通常基于 Libreoffice Calc 单元),对 Andrew Pitonyak 的两本主要书籍(“OpenOffice.org 的有用宏信息”和“OpenOffice.org 宏解释(OOME)”)进行字符串搜索,但之后尝试了大量的片段我一无所获。

Same for libreoffice macro - toggle enablevisible on a textfieldlibreoffice 宏相同- 在文本字段上切换 enablevisible

Any pointer?任何指针?

This is a working snippet (not guaranteed to be the most straightforward, as my experience with macros is one day long):这是一个工作片段(不保证是最直接的,因为我对宏的体验是一天之久):

Sub SetVisibility(oEvent as Object)
    cb2 = ThisComponent.Drawpage.Forms.getByName("MainForm").getByName("Combo2")
    cb2.enableVisible = oEvent.Source.getState()   
    rem the action is activated by Combo1, the event source
End Sub

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

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