TextBox SelectionChanged equivalent?

P

Paul E Collins

I have a toolbar with Cut, Copy and Paste buttons, which need to be enabled
and disabled as appropriate.

I am using SetClipboardViewer and WM_DRAWCLIPBOARD to monitor Clipboard
changes and update the Paste button.

However, I am having trouble with Cut and Copy, which need to be available
whenever there is a selection in the textbox. Surprisingly, there is no
SelectionChanged event for this control.

What is the correct way of monitoring a textbox for a change in selection? I
don't want to use a timer for this unless I have to!

P.
 
J

Julie

Paul said:
I have a toolbar with Cut, Copy and Paste buttons, which need to be enabled
and disabled as appropriate.

I am using SetClipboardViewer and WM_DRAWCLIPBOARD to monitor Clipboard
changes and update the Paste button.

However, I am having trouble with Cut and Copy, which need to be available
whenever there is a selection in the textbox. Surprisingly, there is no
SelectionChanged event for this control.

What is the correct way of monitoring a textbox for a change in selection? I
don't want to use a timer for this unless I have to!

P.

From a Microsoft post:

<quote>
The TextBox does not have a property such as SelectedText as in the
RichTextBox. You will need to programmatically to go check the selection
length, like what you are doing already.
</quote>

So, you are out of luck -- time to resort to timers.

What is even more frustrating is that there *IS* notification of selection
changes in the native Windows control (EN_SELCHANGE). Very poor framework
implementation, maybe someday .Net will actually be a step forward rather than
5 steps backwards...
 
P

Paul E Collins

Julie said:
What is even more frustrating is that there *IS*
notification of selection changes in the native
Windows control (EN_SELCHANGE).

Hmm. Is there a way I could intercept this?

Failing that - MouseUp and KeyPress events will probably cover all possible
text-selecting operations, so perhaps I'll use those rather than a timer.

P.
 
P

Philip Rieck

So, you are out of luck -- time to resort to timers.

What is even more frustrating is that there *IS* notification of selection
changes in the native Windows control (EN_SELCHANGE). Very poor framework
implementation, maybe someday .Net will actually be a step forward rather than
5 steps backwards...


The EN_SELCHANGE event is only for rich edit boxes - the normal edit box
does not fire an EN_SELCHANGE (or any selection change) notification.
 
J

Julie

Philip said:
The EN_SELCHANGE event is only for rich edit boxes - the normal edit box
does not fire an EN_SELCHANGE (or any selection change) notification.

Crap -- you are right.

Second time today that I've had to retract a statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top