Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / September 2006

Tip: Looking for answers? Try searching our database.

Text alignment in TextBox...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David - 13 Sep 2006 20:44 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.