Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Centering Text Vertically
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Centering Text Vertically
Divers
Thread ID:
01436595
Message ID:
01436595
Vues:
92
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
Répondre
Fil
Voir

Click here to load this message in the networking platform