|
-
December 2nd, 2008, 03:04 PM
#1
[RESOLVED] Displaying Text in Label
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,
-
December 3rd, 2008, 05:48 AM
#2
Re: Displaying Text in Label
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 ..
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?
Busy 
-
December 3rd, 2008, 09:55 AM
#3
Re: Displaying Text in Label
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.
-
December 3rd, 2008, 09:14 PM
#4
Re: Displaying Text in Label
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.
Busy 
-
December 4th, 2008, 09:28 AM
#5
Re: Displaying Text in Label
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,
-
December 4th, 2008, 09:48 AM
#6
Re: [RESOLVED] Displaying Text in Label
 Originally Posted by Scott.Macmaster
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:
Code:
Function TextLabelRenderedWidth(ByVal MyLabel As Label) As Integer
With Mylabel
Return .Padding.Left + TextRenderer.MeasureText(.Text, .Font).Width + .Padding.Right
End With
End Function
[Vb.NET 2008 (ex Express)]
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
|