How to derive from textbox to get an autoscroll property?

  • Thread starter Thread starter sherifffruitfly
  • Start date Start date
S

sherifffruitfly

Hi,

I want to derive of of TextBox, and add on an auto-scroll-to-bottom
boolean property. I can use a regular textbox (rich or otherwise) and
get the effect by:

mytextbox.append("my text");
mytextbox.focus();
mytextbox.scrolltocaret();

What sorts of things do I need to look into in order to get a property
in a derived class that has this effect?

Thanks for any direction,

cdj
 
sherifffruitfly said:
Hi,

I want to derive of of TextBox, and add on an auto-scroll-to-bottom
boolean property. I can use a regular textbox (rich or otherwise) and
get the effect by:

mytextbox.append("my text");
mytextbox.focus();
mytextbox.scrolltocaret();

What sorts of things do I need to look into in order to get a property
in a derived class that has this effect?

Thanks for any direction,

cdj

Inherit from textbox, add your property and override OnTextChanged and
do your processing in there.

JB
 
Additionally, it should be stated that calling the focus method is not
advisable. If I was on another control and the focus was suddenly taken
from me, I'd be pissed.
 
Additionally, it should be stated that calling the focus method is not
advisable. If I was on another control and the focus was suddenly taken
from me, I'd be pissed.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Inherit from textbox, add your property and override OnTextChanged and do
your processing in there.

Then I have no idea how to get the textbox to scroll. According to
msdn, the textbox must have focus in order for scrolltocaret to work.
In particular, there simply IS NO CARET unless the textbox has focus.

I'm open to any workaround ideas. (This issue is really why I asked
the question in the first place.)
 
sherifffruitfly said:
Then I have no idea how to get the textbox to scroll. According to
msdn, the textbox must have focus in order for scrolltocaret to work.
In particular, there simply IS NO CARET unless the textbox has focus.

I'm open to any workaround ideas. (This issue is really why I asked
the question in the first place.)

Yeah. I've run into that before. One more example of why the built-in
controls in Windows Forms are half-baked.

Try using a COM-based textbox. Yeah it's old-school but it's better than
stealing focus...

Jon
 
Yeah. I've run into that before. One more example of why the built-in
controls in Windows Forms are half-baked.

Is there any way to "remember" what object had focus when the textbox
stole it,
and return focus to that object when the and return focus to it when
the textbox
is done scrolling/updating?
 
Back
Top