开发者

WX: attempting to select value when clicking a text field

We are implementing a text field to do numeric entry. We subclass the standard wxTextCtrl. Behavior is that when user decides to edit the value they get a full precision version and it is selected.

First attempt was to override the focus handler so that when the field gets focus the value is shown in full and selected. This works great except for the cases when you click on the field. In that case, the focus handler is called and the value is selected...but some time after that it is deselected and the edit point put where the mouse click occurred. I thought maybe I could override SetSelection and set a debug point but it seems to use some other method to set the selection! I'm stuck having to walk through the miles of event handling crap to figure it out...I'm thinking in the mouse button handlers but so far I haven't found a开发者_StackOverflowny.

It would be nice if someone who might already know what I need to override to point it out. Where do I need to be looking?


I would try this code for your wxTextCtrl (but I'm not sure if this is what you want - focus and click)

m_textCtrl1->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( MyDialog1::LeftDown ), NULL, this );
m_textCtrl1->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( MyDialog1::SetFocus ), NULL, this );


void LeftDown( wxMouseEvent& event );
void SetFocus( wxFocusEvent& event );

In case what you do is overwritten by the default (system) handler of your control you could try 'wxPostEvent' to do what you want later (after the default handling).

I also suggest using a designer for this (for this question I stole some code generated by wxFormBuilder)


Answer is that it can't be done. The behavior I'm trying to override is implemented by the win32 component itself and wx doesn't provide any method to doing so....short of bypassing WX to get the win32 handle and using win32 api.

Would need to write a new component in the WX api to get the desired behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜