【问题标题】:How to receive drop events in a wxTextCtrl?如何在 wxTextCtrl 中接收放置事件?
【发布时间】:2011-01-03 10:25:44
【问题描述】:

我有一个覆盖 OnDropFiles 的 wxTextCtrl 派生类。但是,将某些东西拖到控件上没有任何作用。 (光标变为“不允许”光标。)我尝试了 DragAcceptFiles(true) ,但这仅启用了内置的放置处理程序。 (这只是将文件加载到控件中。)我怎样才能调用我自己的处理程序?

我也尝试过 SetDropTarget,但它也从未被调用过。不过,它在 wxFrame 中工作。

有什么想法吗?

【问题讨论】:

    标签: drag-and-drop wxwidgets wxtextctrl


    【解决方案1】:

    这是我在其中一个项目中的精简版:

    我的表单代码

    wxTextCtrl* textctrl = new wxTextCtrl(...);
    textctrl->SetDropTarget(new DropFiles(textctrl));
    

    dropfiles 类

    class DropFiles: public wxFileDropTarget{
    public:
        DropFiles(wxTextCtrl *text): m_Text(text){}
        bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& arrFilenames);
    
    private:
        wxTextCtrl *m_Text;
    };
    
    bool DropFiles::OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxArrayString& arrFilenames){
        //Just take the first filename
        m_Text->SetValue(arrFilenames.Item(0));
        return true;
    }
    

    希望有帮助!

    【讨论】:

    • 感谢您的尝试,但这仍然不起作用 - OnDropFiles 永远不会被调用。不过,我确实找到了解决方案。看我的回答。
    • 奇怪,我当然不会处理它,我猜是因为你可能是从 wxTextCtrl 派生的?
    【解决方案2】:

    您必须处理 EVT_DROP_FILES 事件。任何其他获得通知的尝试都将失败:(

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-04
      相关资源
      最近更新 更多