c# - TextBox.TextAlign right-side alignment has no effect in certain conditions? -


i have path selector in visual c# express 2010 form application.

i using folderbrowserdialog , (single line) textbox, show selected path. using following line in ui refresh code.

this.textboxfolder.text = this.folderbrowserdialog1.selectedpath; 

the readonly property set true , textalign property set right using form designer, because selected path longer textbox, , prefer show right-side of path. forms designer generates this:

//  // textboxfolder //  this.textboxfolder.location = new system.drawing.point(40, 72); this.textboxfolder.name = "textboxfolder"; this.textboxfolder.readonly = true; this.textboxfolder.size = new system.drawing.size(160, 20); this.textboxfolder.tabindex = 13; this.textboxfolder.tabstop = false; this.textboxfolder.textalign = system.windows.forms.horizontalalignment.right; 

whenever chosen path shorter textbox size, right alignment works. (but not important)

whenever chosen path longer textbox size, right alignment has no effect, string in textbox displayed such left-most character visible, , right-most hidden.

i know in normal single line textbox (readonly = false), when overly-long string typed in hand, right chars visible, when focus goes away, regardless of whether textalign set left / right / center!

in other words, goal is, when textbox.text programmatically set (as opposed typed in), , string longer width of textbox, how right-most chars visible?

instead of setting textalign property, should move caret last character:

textboxfolder.text = this.folderbrowserdialog1.selectedpath; textboxfolder.selectionstart = textbox1.text.length - 1; 

setting selectionstart moves caret specified position. , makes character @ position visible in textbox.

if can use label instead of text box, can use one created hans passant here uses textformatflags.pathellipses flag while drawing text.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -