I am developing a Windows Form Application. I want to Align the Text to Center or say to Right of Title Bar of Form. How can I do it ??
It can be done with custom form - you will have to create your own title bar. See V4Vendettas comment;
Other approach (link) - is to create your own handler for form resize and insert there followong code. It will add appropriate amount of spaces from the left size of text. However you will have to add form.Refresh() and call that method in form.Load; also your window will have "..." as a text in task bar.
private void UpdateTextPosition()
{
Graphics g = this.CreateGraphics();
Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
String tmp = " ";
Double tmpWidth = 0;
while ((tmpWidth + widthOfASpace) < startingPoint)
{
tmp += " ";
tmpWidth += widthOfASpace;
}
this.Text = tmp + this.Text.Trim();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With