0

How would I prevent a string in a System.Windows.Forms.Label from wrapping to a second line? If I set the size to, say, 90x20 and the text extends past 90px, it'll wrap and you see the top of the wrapped text underneath the other text.

I can change the height from 20 to 15 and it hides the wrapped text, but the text is of course still wrapping.

I set the width to 90 because if I don't, it'll overlap over the object to the right. So how would I actually prevent the text from wrapping? Or if you have an idea how I can better accomplish this I'm open to it.

jerdub1993
  • 355
  • 1
  • 8
  • what is wrong with changing the height to 15 to hide the wrapped text like you said. it would be hidden by the object to the right and your width constraint if it didn't wrap right? – frankM_DN Nov 03 '22 at 14:16
  • [Set `$label.MaximumSize = [System.Drawing.Size]::new(90,0)` and `$label.AutoSize = $true`](https://stackoverflow.com/questions/1204804/word-wrap-for-a-label-in-windows-forms) – Mathias R. Jessen Nov 03 '22 at 14:17

1 Answers1

1

You can set these properties to your label (let's call it '$myLabel')

$myLabel.Size         = '90, 20'
$myLabel.AutoSize     = $false
$myLabel.AutoEllipsis = $true

This will truncate lines of text that are too long and append ... to it, denoting that there is more text than can be displayed

Theo
  • 57,719
  • 8
  • 24
  • 41