Use TextRenderer.DrawText with the TextFormatFlags.PathEllipsis flag
void label_Paint(object sender, PaintEventArgs e) { Label label = (Label)sender; TextRenderer.DrawText(e.Graphics, label.Text, label.Font, label.ClientRectangle, label.ForeColor, TextFormatFlags.PathEllipsis); }
Your code there is 95%. The only problem is that the cropped text is at the top of the text, which is already on the label.
Yes, thanks, I knew about that. My intention was to demonstrate the use of the DrawText method. I did not know if you want to manually create an event for each label or simply override the OnPaint() method in the inherited label. Thank you for sharing your final decision.
lubos hasko
source share