Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Centering Text Vertically
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Centering Text Vertically
Miscellaneous
Thread ID:
01436595
Message ID:
01436595
Views:
91
I'm using OnPaint to draw a string:
protected override void OnPaint(PaintEventArgs e)
{
    Label lbl = new Label();
    lbl.Text = _Text;   // Property called Text

    Font font = new Font("Arial", 10);
    SolidBrush brush = new SolidBrush(Color.Black);

    StringFormat format = new StringFormat();

    e.Graphics.DrawString(_Text, font, brush, 5, (Height / 2) - (lbl.Height / 2) , format);

    base.OnPaint(e);
}
To center the text top to bottom, I have created a label, set it's text to the text I wan to show, then used the label to determine the
height of the tex.

Anyone know a better way to do this?

Thanks
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Reply
Map
View

Click here to load this message in the networking platform