Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.55 KB | None | 0 0
  1. private void Center_Text()
  2.         {
  3.             Graphics g = this.CreateGraphics();
  4.             Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
  5.             Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
  6.             String tmp = " ";
  7.             Double tmpWidth = 0;
  8.             while ((tmpWidth + widthOfASpace) < startingPoint)
  9.             {
  10.                 tmp += " ";
  11.                 tmpWidth += widthOfASpace;
  12.             }
  13.             this.Text = tmp + this.Text.Trim();
  14.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement