By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,515 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,515 IT Pros & Developers. It's quick & easy.

Textbox "cut" text with "..."

P: 47
Hi,
is there some sort of setting or function where you can cut the text of a textbox with "..." like you sometimes see at the browse field of an installer?
example

c:\folder\subfolder\things\file.ext
to
c:\folder\su...\file.ext
Mar 4 '09 #1
Share this Question
Share on Google+
5 Replies


vekipeki
Expert 100+
P: 229
You might use
Expand|Select|Wrap|Line Numbers
  1. [DllImport( "shlwapi.dll" )]
  2. static extern bool PathCompactPathEx
  3.    ( [Out] StringBuilder pszOut,
  4.      string szPath,
  5.      int cchMax,
  6.      int dwFlags );
If you are actually drawing the string using TextRenderer, then it will do the job for you. Or you can try to code it yourself - System.IO.DirectoryInfo will get you all the folder information you need from a string.
Mar 4 '09 #2

P: 47
its just a textbox with a string in it to a certain path the user selects. so im not sure what lies behind that.
but its a textbox in which the user can type his/her path as well, maybe that could be a problem?
Mar 4 '09 #3

tlhintoq
Expert 2.5K+
P: 3,525
@Meganutter
"Problem"? You didn't mention any problem in the original post.
Personally, I never trust a user to type in a path. They will NOT get it right.
I always use a button to file or folder browse dialog. You can then display the path (including your ellipse in the middle if you like) in a read-only text box. This way you are guaranteed the path to be accurate, the folder or server to be accessible at that time, and you can display as you like without fear of the use typing in a change that invalidates the whole thing.
Mar 4 '09 #4

P: 47
i was asking if that might be something that could make a problem. but you explained pretty well i guess...
ill put it to read only and will try the previous post code
Mar 4 '09 #5

P: 47
it worked thanks for the help, i added the PathCompactPathEx and tried something, i dont know what the dwFlags does though but it seems to be working when set to 1
Mar 5 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.