-
Oct 22nd, 2008, 03:06 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2008] Adding "..." to long text
I have a problem with some of the files i work with, the names are too long when they show up in the label and i want to add "..." to the shorten the text. So lets say after 5 letters it add "..."
-
Oct 22nd, 2008, 03:14 PM
#2
Hyperactive Member
Re: [2008] Adding "..." to long text
This should work...
vb Code:
Dim filename as String Dim truncatedName As String If filename.Length > 5 Then truncatedName = filename.Substring(0, 5) + "..." End If
Last edited by wy125; Oct 22nd, 2008 at 03:38 PM.
-
Oct 22nd, 2008, 03:17 PM
#3
Re: [2008] Adding "..." to long text
try this:
vb Code:
Private Sub update_label(ByVal newDir As String)
Dim gr As Graphics = Graphics.FromHwnd(Label1.Handle.ToInt32)
Dim nextSlash As Integer = newDir.IndexOf("\")
Dim lastSlash As Integer = newDir.LastIndexOf("\")
'change width for your label
If gr.MeasureString(newDir, Label1.Font).Width > 600 And nextSlash > -1 And lastSlash > nextSlash Then
Do
Dim rLength As Integer = newDir.IndexOf("\", nextSlash + 1) - nextSlash
If rLength < 1 Then Exit Do
newDir = newDir.Replace(newDir.Substring(nextSlash + 1, rLength - 1), "...")
nextSlash = newDir.IndexOf("\", nextSlash + 1)
If gr.MeasureString(newDir, Label1.Font).Width <= 600 Then Exit Do
If nextSlash = -1 Then Exit Do
Loop
End If
Me.Label1.Text = newDir
Me.Label1.Refresh()
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 22nd, 2008, 03:24 PM
#4
Thread Starter
Hyperactive Member
Re: [2008] Adding "..." to long text
Im having a look at both and i have a question.. where do u guys declare "s" and "newDir"?
-
Oct 22nd, 2008, 03:27 PM
#5
Thread Starter
Hyperactive Member
Re: [2008] Adding "..." to long text
Heres my problem. And if you can explain to me what exactly u did so ill remember plz and thanks
-
Oct 22nd, 2008, 03:30 PM
#6
Re: [2008] Adding "..." to long text
you call it like this:
it'll shorten filename + display it in label1. don't forget to read my comments in the code.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 22nd, 2008, 03:31 PM
#7
Re: [2008] Adding "..." to long text
i'd also recommend setting your labels autosize property to false
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 22nd, 2008, 03:35 PM
#8
Re: [2008] Adding "..." to long text
Set the AutoEllipsis property to true, AutoSize to false on the label...
That is all you have to do
-
Oct 22nd, 2008, 03:35 PM
#9
Thread Starter
Hyperactive Member
Re: [2008] Adding "..." to long text
But where does the "s" in "s.Substring" come from?
-
Oct 22nd, 2008, 03:35 PM
#10
Lively Member
Re: [2008] Adding "..." to long text
-
Oct 22nd, 2008, 03:36 PM
#11
Re: [2008] Adding "..." to long text
how about this.
Code:
Label2.AutoSize = False
Label2.AutoEllipsis = True
Label2.Text = "THIS IS WAY TO LONG FOR THE LABEL. KISS"
i see that matt, once again, is a faster typer than i.
-
Oct 22nd, 2008, 03:37 PM
#12
Thread Starter
Hyperactive Member
Re: [2008] Adding "..." to long text
kleinma your a funny one, thanks.. i didnt know it was that simple
-
Oct 22nd, 2008, 03:39 PM
#13
Re: [RESOLVED] [2008] Adding "..." to long text
but i gave an example
Last edited by dbasnett; Oct 22nd, 2008 at 03:50 PM.
-
Oct 22nd, 2008, 03:39 PM
#14
Hyperactive Member
Re: [2008] Adding "..." to long text
Originally Posted by youngbucks
Im having a look at both and i have a question.. where do u guys declare "s" and "newDir"?
s was not declared by mistake it should have been filename. it has been corrected....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|