|
-
Aug 8th, 2003, 03:45 PM
#1
Thread Starter
Hyperactive Member
MeasureString problem [RESOLVED]
I'm making an invoice printing program and I would like to print the invoice number in a box and center it automatically.
VB Code:
Dim invSize As SizeF = e.Graphics.MeasureString(InvNumber, fFont)
Dim iX As Integer
iX = 560 + (200 - CInt(invSize.Width) / 2)
The number is now right justified in the box, not in the center. What am I doing wrong?
560 is the x coordinate of the box, and 200 is the width.
Last edited by wolfrose; Aug 8th, 2003 at 04:48 PM.
-
Aug 8th, 2003, 04:03 PM
#2
Made its the math order try:
VB Code:
iX = 560 + (200 - (CInt(invSize.Width) / 2))
-
Aug 8th, 2003, 04:08 PM
#3
Thread Starter
Hyperactive Member
VB does multiplication and division before addition and subtraction. I tried it just in case, but to no avail.
-
Aug 8th, 2003, 04:25 PM
#4
So where is it putting the box? Do you have some sample code we can use to test?
-
Aug 8th, 2003, 04:32 PM
#5
Thread Starter
Hyperactive Member
VB Code:
e.Graphics.DrawString("Invoice Number", bFont, Brushes.Black, 590, 250)
e.Graphics.DrawRectangle(fPen, 570, 275, 200, 30)
-
Aug 8th, 2003, 04:40 PM
#6
I put the parathesis on the wrong one is all. Try this:
VB Code:
iX = 560 + ((200 - CInt(invSize.Width)) / 2)
e.Graphics.DrawString("Invoice Number", bFont, Brushes.Black, iX, 250)
The fact that is does the division first is what messed it up.
Here is how I tested:
VB Code:
Dim txt As String = "Center Me Please"
Dim defFont As New Font("Tahoma", 14)
Dim boxStartx As Integer = 560
Dim boxStarty As Integer = 275
Dim boxWidth As Integer = 200
Dim txtSize As SizeF = e.Graphics.MeasureString(txt, defFont)
Dim start As Integer = boxStartx + ((boxWidth - Convert.ToInt32(txtSize.Width)) / 2)
e.Graphics.DrawString(txt, defFont, Brushes.Black, start, boxStarty)
e.Graphics.DrawRectangle(New Pen(Color.Black), boxStartx, boxStarty, 200, 30)
-
Aug 8th, 2003, 04:47 PM
#7
Thread Starter
Hyperactive Member
That's better. I changed the 560 to 570, and it is better centered. Thanks for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|