[英]How to disable a wxTextCtrl Widget in wxWidgets C++?
I'm writing a wxWidgets program in C++.我正在用 C++ 编写一个 wxWidgets 程序。 It has several single line wxTextCtrls in it and I need to disable them so the user cannot enter text in them.
它有几个单行 wxTextCtrls,我需要禁用它们,以便用户无法在其中输入文本。 Later, when a menu item is clicked, I want to enable them again.
稍后,当单击菜单项时,我想再次启用它们。 How do I do this?
我该怎么做呢?
Since wxTextCtrl
is a subclass of wxWindow
, it contains (probably overridden) virtual method Enable
of wxWindow
, documentation for which can be found here and which controls whether the window is enabled for user input according to its boolean argument (which defaults to true
- enable input).由于
wxTextCtrl
是wxWindow
的子类,它包含(可能被覆盖) wxWindow
的虚拟方法Enable
,可以在此处找到其文档,并根据其布尔参数(默认为true
- enable)控制是否为用户输入启用窗口输入)。 Also, there is a handy non-virtual Disable
method, which is defined to be equivalent to Enable(false)
.此外,还有一个方便的非虚拟
Disable
方法,它被定义为等效于Enable(false)
。
You can use it like this to disable text control (assuming you save pointer to your wxTextCtrl
instance in a m_pTextCtrl
member of your window class):您可以像这样使用它来禁用文本控制(假设您将指向
wxTextCtrl
实例的指针保存在窗口类的m_pTextCtrl
成员中):
m_pTextCtrl = new wxTextCtrl(...);
// ...
m_pTextCtrl->Disable();
and like this to enable it in your menu item event handler:并像这样在您的菜单项事件处理程序中启用它:
m_pTextCtrl->Enable();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.