|
Hi I have created a custom control extended from label. Below is what I am doint on PAINT event. I am just writing TEXT in label using TEXTRENDERER method, but though my lable is of say height 100, its just showing ONE line of TEXT... why isn't multiple line being shown, even though label height is more...? protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); pe.Graphics.FillRectangle(new SolidBrush(base.BackColor), pe.ClipRectangle); TextRenderer.DrawText(pe.Graphics, base.Text, base.Font, pe.ClipRectangle, Color.Black, Color.White, TextFormatFlags.EndEllipsis); } Another query..is there any method through which we can know what clipped text is in label after we use AUTOELLIPSE property. Thanks and Regards. | | sujit1779 Saturday, September 19, 2009 10:55 AM | First off, using pe.ClipRectangle is wrong, you must use this.ClientRectangle. You'll see that when you slowly move another window across your form. Next, you must use the proper TextFormatFlags to tell it to break the line across multiple lines. Use WordBreak. Sample code is here. No, you can't get the clipped text, you'd have to clip yourself.
Hans Passant. - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 8:07 AM
-
| | nobugz Saturday, September 19, 2009 11:09 AM | You are not asking for ellipses anymore. Not that it will work, TextRenderer will only use ellipses on single lines of text. You've disabled that by using TextFormatFlags.WordBreak. Adding them yourself is the only workaround, it takes tricky MeasureText code to do so.
Hans Passant.- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 8:07 AM
-
| | nobugz Saturday, September 19, 2009 1:07 PM | First off, using pe.ClipRectangle is wrong, you must use this.ClientRectangle. You'll see that when you slowly move another window across your form. Next, you must use the proper TextFormatFlags to tell it to break the line across multiple lines. Use WordBreak. Sample code is here. No, you can't get the clipped text, you'd have to clip yourself.
Hans Passant. - Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 8:07 AM
-
| | nobugz Saturday, September 19, 2009 11:09 AM | Hi , thanks for the reply. This is what I am using now, still I couldn't get the ellipse (i.e. dot dot dot) when the text truncates. pe.Graphics.FillRectangle(new SolidBrush(base.BackColor), pe.ClipRectangle); Rectangle rect = this.ClientRectangle; TextRenderer.DrawText(pe.Graphics,base.Text, this.Font, rect, base.ForeColor, base.BackColor, TextFormatFlags.WordBreak); Can you tell me what wrong I am doing ? Thanks. | | sujit1779 Saturday, September 19, 2009 12:06 PM | You are not asking for ellipses anymore. Not that it will work, TextRenderer will only use ellipses on single lines of text. You've disabled that by using TextFormatFlags.WordBreak. Adding them yourself is the only workaround, it takes tricky MeasureText code to do so.
Hans Passant.- Marked As Answer byAland LiMSFT, ModeratorTuesday, September 22, 2009 8:07 AM
-
| | nobugz Saturday, September 19, 2009 1:07 PM |
|