I have a .NET 1.1 textbox that displays a file name with path. When the
path+name is too long to fit in the textbox, I would like to display only the
right-most characters (the filename, truncating the path part, but still
horizontally scrollable).
Setting the TextAlign property to "Right" doesn't really help much, because
when the path+name is short enough to fit completely in the textbox, it
really looks weird to have it right-justified, with blank-fill on the left.
I guess what I would really like is, in effect, the ability to left-justify
when the text fits, but right-justify when it doesn't.
If there isn't a variant of the TextBox or RichTextBox that does this,
could I inherit TextBox and maybe override its Paint (or some other method)
to do what I want? Is there a source of examples of inheriting TextBox to do
something similar? I've only inherited a control and over-ridden its Paint
method once, and that was based on an example, so while I understand the
concept, the details of directly drawing the control are still a bit fuzzy...
Thanks for any advice,
D
David - 13 Sep 2006 21:03 GMT
I found the answer just after posting this question...
After setting the Text property of the TextBox, simply do:
textbox.SelectionStart = textbox.TextLength
That will have the desired effect.
D
> I have a .NET 1.1 textbox that displays a file name with path. When the
> path+name is too long to fit in the textbox, I would like to display only the
[quoted text clipped - 18 lines]
>
> D