0

I am having problems trying to center some text. I created a printdocument and it has a company name and title and then other information I have the information fine but I wanted to center the company name and I can't seem to do it correctly here is what I have

ResultMessage = "Valley boulevard Auto Center"
        HorizontalPrintLocSingle = Convert.ToSingle((e.PageBounds.Width / 2) - (szF.Width / 2))
        e.Graphics.DrawString(ResultMessage, HeadingFont, Brushes.Black, HorizontalPrintLocSingle, VerticalPrintLocSingle)

What Am I doing wrong. I know I have to get the width of the page then divide it by two and after that find out how long my
text is then subtract that so it still prints center screen. Pretty much right now it prints out and runs off the right side of the page...But what I would like it to do is print in the Center but have equal margins on the sides of the page still. Just like clicking Center allignment on a word doc. Any help?

1
Contributor
1
Reply
4
Views
5 Years
Discussion Span
Last Post by irishsailor
0

I might have figured it out on my own... Does this look right?

Center = Convert.ToSingle(e.PageBounds.Width / 2 - e.Graphics.MeasureString("Valley boulevard Auto Center", HeadingFont).Width / 2)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.