Click to See Complete Forum and Search --> : [RESOLVED] Displaying Text in Label
Scott.Macmaster
December 2nd, 2008, 02:04 PM
I'm working on a something like a custom grid control. Everything is working fine except when I show plain text in label. If I have text in the label that doesn't fit it'll either overlap the next column or wrap to the next line depending on whether I set AutoSize or not. I don't want either behavior. I want the text to stay in one line and simply be truncated at the end of label control. Is there a way to get this to work how I want it to?
Thanks,
Thread1
December 3rd, 2008, 04:48 AM
i had the same situation but that was in a form designer where there is the features bring-to-front and send-to-back for all its controls :D..
anyways, how did you design the grid? is that your own grid design with raw graphics or you just reused some of the standard controls such as labels?
Scott.Macmaster
December 3rd, 2008, 08:55 AM
Currently, it's made entirely from controls. However, if I can't get the labels to display the text how I want I've have to draw the text myself. It'll be more efficient if I draw the text myself anyway. Currently, it takes several seconds to add all the controls.
Thread1
December 3rd, 2008, 08:14 PM
actually, you could also display the text with the labels. turning off the autosize property and then manage the size of the labels (same size with the column) will clip the content.
on the otherhand, if you going to use some raw graphics you would need a canvass to draw from which should be your main container control. it could be a picturebox control. and on paint event you could get reference to its graphics object, and then perform your string drawings there. however, why wouldn't use the gridview or datagrid? you could inherit some of their built-in features.
Scott.Macmaster
December 4th, 2008, 08:28 AM
Well, that's what I did to start with. The problem was the text would wrap to the next line which resulted in large portions of the text not being visible. If the label control had a MultiLine property that I could set the false like the text box it would work for me.
As for the DataGridView, it doesn't have a numeric up/down control for the column type.
In any case, it doesn't really matter I just finished implementing a better solution. I dropped all the label controls and now I'm drawing all the text myself in OnPaint(). I even have the ... thing if the text doesn't fit. Also, now that I have about 700 less controls creating the grid takes a second less and the redraw looks nicer.
However, it still takes 4-5 seconds to create the grid. Maybe I'll drop the textbox and numeric up/downs controls and draw them myself.
Thanks,
Marraco
December 4th, 2008, 08:48 AM
I'm working on a something like a custom grid control. Everything is working fine except when I show plain text in label. If I have text in the label that doesn't fit it'll either overlap the next column or wrap to the next line depending on whether I set AutoSize or not. I don't want either behavior. I want the text to stay in one line and simply be truncated at the end of label control. Is there a way to get this to work how I want it to?
...If you can set the container width, you can get the required label width width this way:
Function TextLabelRenderedWidth(ByVal MyLabel As Label) As Integer
With Mylabel
Return .Padding.Left + TextRenderer.MeasureText(.Text, .Font).Width + .Padding.Right
End With
End Function
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.