Discussion:
VB6 - Label - force single-line display?
(too old to reply)
Robert
2004-02-26 11:28:03 UTC
Permalink
Hello,

does anyone know how to force a label to display its contents single-line
(even when this means cutting of text at the end?
My label is just high enough for 1 text line, WordWrap is false, and still
the second word would wrap to the (invisible) second line if it's too long!

Thanks

Robert
Jan Hyde
2004-02-26 12:46:49 UTC
Permalink
"Robert" <***@nowhere.com>'s wild thoughts were released
on Thu, 26 Feb 2004 12:28:03 +0100 bearing the following
Post by Robert
Hello,
does anyone know how to force a label to display its contents single-line
(even when this means cutting of text at the end?
My label is just high enough for 1 text line, WordWrap is false, and still
the second word would wrap to the (invisible) second line if it's too long!
You could set AutoSize = True, WordWrap = false and then
manually set the width

Label1.Caption = "This is a long piece of text in a label
control"
Label1.Width = 400

or you could put the label in a container and let the label
autosize.
--
Jan Hyde (MVP - Visual Basic)

The average guy thinks about sex once every six tits

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Robert
2004-02-26 14:30:53 UTC
Permalink
Post by Jan Hyde
or you could put the label in a container and let the label
autosize.
Thanks for that idea. As it happens, the label is already in a
container...just didn't think of it that way.

Robert
lance
2004-02-26 13:38:14 UTC
Permalink
you could try the PathCompactPathEx API function, althought this really
truncates a path to fit within a certain number of characters by replacing
path components with ellipses. i suppose it could be applied to any string,
not just a path.

from the API guide:


Private Declare Function PathCompactPathEx Lib "shlwapi.dll" Alias
"PathCompactPathExA" (ByVal pszOut As String, ByVal pszSrc As String, ByVal
cchMax As Long, ByVal dwFlags As Long) As Long

Dim sSave As String
sSave = String(255, 0)
'truncate a path to fit within 20 characters by replacing path components
with ellipses.
PathCompactPathEx sSave, "C:\This\is\a\long\path\myfile.txt", 20, 0
'show the result
Me.Print StripTerminator(sSave)

Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
Post by Robert
Hello,
does anyone know how to force a label to display its contents single-line
(even when this means cutting of text at the end?
My label is just high enough for 1 text line, WordWrap is false, and still
the second word would wrap to the (invisible) second line if it's too long!
Thanks
Robert
lance
2004-02-26 13:54:04 UTC
Permalink
on second thought, i think it really only works on paths.

lance
Post by lance
you could try the PathCompactPathEx API function, althought this really
truncates a path to fit within a certain number of characters by replacing
path components with ellipses. i suppose it could be applied to any string,
not just a path.
Private Declare Function PathCompactPathEx Lib "shlwapi.dll" Alias
"PathCompactPathExA" (ByVal pszOut As String, ByVal pszSrc As String, ByVal
cchMax As Long, ByVal dwFlags As Long) As Long
Dim sSave As String
sSave = String(255, 0)
'truncate a path to fit within 20 characters by replacing path components
with ellipses.
PathCompactPathEx sSave, "C:\This\is\a\long\path\myfile.txt", 20, 0
'show the result
Me.Print StripTerminator(sSave)
Function StripTerminator(sInput As String) As String
Dim ZeroPos As Long
ZeroPos = InStr(1, sInput, Chr$(0))
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
Post by Robert
Hello,
does anyone know how to force a label to display its contents single-line
(even when this means cutting of text at the end?
My label is just high enough for 1 text line, WordWrap is false, and still
the second word would wrap to the (invisible) second line if it's too
long!
Post by Robert
Thanks
Robert
Mike D Sutton @ Work
2004-02-26 14:50:45 UTC
Permalink
Post by lance
on second thought, i think it really only works on paths.
Calling DrawText() with the DT_END_ELLIPSIS/DT_WORD_ELLIPSIS and DT_MODIFYSTRING flags would give you the string with ellipses at
the end.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ***@mvps.org
WWW: Http://www.mvps.org/EDais/
lance
2004-02-26 15:01:43 UTC
Permalink
ahh...that's the one i was *really* looking for! there's just way too many
API functions to keep track of. i've probably wasted half my time trying to
duplicate the functionality of an API function that i didn't know existed.
Post by Mike D Sutton @ Work
Post by lance
on second thought, i think it really only works on paths.
Calling DrawText() with the DT_END_ELLIPSIS/DT_WORD_ELLIPSIS and
DT_MODIFYSTRING flags would give you the string with ellipses at
Post by Mike D Sutton @ Work
the end.
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
WWW: Http://www.mvps.org/EDais/
Randy Birch
2004-02-27 00:23:09 UTC
Permalink
Here's a link ... http://vbnet.mvps.org/code/textapi/strellipse.htm
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.


"lance" <***@there.com> wrote in message news:eMhpGlH$***@TK2MSFTNGP11.phx.gbl...
: ahh...that's the one i was *really* looking for! there's just way too
many
: API functions to keep track of. i've probably wasted half my time trying
to
: duplicate the functionality of an API function that i didn't know existed.
:
:
: "Mike D Sutton @ Work" <***@mvps.org> wrote in message
: news:O9bwEgH$***@TK2MSFTNGP10.phx.gbl...
: > > on second thought, i think it really only works on paths.
: >
: > Calling DrawText() with the DT_END_ELLIPSIS/DT_WORD_ELLIPSIS and
: DT_MODIFYSTRING flags would give you the string with ellipses at
: > the end.
: > Hope this helps,
: >
: > Mike
: >
: >
: > - Microsoft Visual Basic MVP -
: > E-Mail: ***@mvps.org
: > WWW: Http://www.mvps.org/EDais/
: >
: >
:
:
Loading...