How to derive from textbox to get an autoscroll property?

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
 
J

John B

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

sherifffruitfly

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.)
 
J

Jon Davis

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
 
S

sherifffruitfly

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?
 

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