如何使用鼠标左键双击启用/禁用 wxRadioBox 项目
在 wxWidgets 2.8 下,我想使用鼠标左键双击标识该项目的标签来启用或禁用 wxRadioBox 项目。 为此,我计划使用 GetItemFromPoint 来识别该项目。
问题是,当双击 wxRadioBox 时,我无法捕获鼠标事件,无论是在父面板上,还是使用 wxRadioBox 的派生类。
示例代码
中的 .h 文件中的
class PrinterRadioBox: public wxRadioBox
{
public:
PrinterRadioBox(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& point, const wxSize& size, int n, const wxString choices[], int majorDimension, long style, const wxValidator& validator, const wxString& name)
: wxRadioBox(parent,id, label, point, size, n, choices, majorDimension, style, validator, name)
{
}
PrinterRadioBox(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& point, const wxSize& size, const wxArrayString& choices, int majorDimension = 0, long style = wxRA_SPECIFY_COLS, const wxValidator& validator = wxDefaultValidator, const wxString& name = "radioBox")
: wxRadioBox(parent, id, label, point, size, choices, majorDimension, style, validator, name)
{
}
void OnLeftDClick(wxMouseEvent& event);
private:
DECLARE_NO_COPY_CLASS(PrinterRadioBox)
DECLARE_EVENT_TABLE()
};
.cpp 文件
BEGIN_EVENT_TABLE(PrinterRadioBox, wxRadioBox)
EVT_LEFT_DCLICK(PrinterRadioBox::OnLeftDClick)
END_EVENT_TABLE()
void PrinterRadioBox::OnLeftDClick(wxMouseEvent& event)
{
wxMessageBox("here radio box");
event.Skip();
}
如何通过双击选择 wxRadioBox 的单个项目(元素)来启用或禁用它?
Under wxWidgets 2.8 I want to enable or disable a wxRadioBox item using a mouse left double click on the label which identify the item.
To this end I plan to use the GetItemFromPoint to identify the item.
The problem is that I cant't able to capture the mouse event when do a double click over the wxRadioBox, neither on the parent panel, nor using a derived class of wxRadioBox.
A sample code
in .h file
class PrinterRadioBox: public wxRadioBox
{
public:
PrinterRadioBox(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& point, const wxSize& size, int n, const wxString choices[], int majorDimension, long style, const wxValidator& validator, const wxString& name)
: wxRadioBox(parent,id, label, point, size, n, choices, majorDimension, style, validator, name)
{
}
PrinterRadioBox(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& point, const wxSize& size, const wxArrayString& choices, int majorDimension = 0, long style = wxRA_SPECIFY_COLS, const wxValidator& validator = wxDefaultValidator, const wxString& name = "radioBox")
: wxRadioBox(parent, id, label, point, size, choices, majorDimension, style, validator, name)
{
}
void OnLeftDClick(wxMouseEvent& event);
private:
DECLARE_NO_COPY_CLASS(PrinterRadioBox)
DECLARE_EVENT_TABLE()
};
in .cpp file
BEGIN_EVENT_TABLE(PrinterRadioBox, wxRadioBox)
EVT_LEFT_DCLICK(PrinterRadioBox::OnLeftDClick)
END_EVENT_TABLE()
void PrinterRadioBox::OnLeftDClick(wxMouseEvent& event)
{
wxMessageBox("here radio box");
event.Skip();
}
How can I enable or disable a single item (element) of a wxRadioBox by selecting it with a double click?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少在wxMSW中,
wxRadioBox
是一个复合本机控件,由一个框和其中的按钮组成,您在捕获这些事件时会遇到问题。如果您确实需要这样做,请考虑使用单独的wxRadioButton
。我还相信
wxRadioBox
实现自 2.8 以来已经发生了变化(很难记住 10 年前版本的所有细节......),所以你真的应该切换到更新的 wx 版本。At least in wxMSW,
wxRadioBox
is a composite native control consisting of a box and the buttons inside it and you're going to have problems catching events from those. If you really need to do this, consider using individualwxRadioButton
s instead.I also believe
wxRadioBox
implementation has changed since 2.8 (hard to remember all the details for 10+ year old version...), so you really should switch to a more recent wx version.