![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Printing. DrawLine/DrawString. C# [WIN] Hi Everyone, My problem is this: I'm having a hard time lining up Graphics.DrawString and Graphics.DrawLine. In that I'm not being able to control the placement of the lines being drawn to my printer after the header. The "y" co-ordinates are all fine and dandy with DrawString (Text), but they get messed up with DrawLine and not being placed exactly co-ordinates where I want them to be drawn. Co-ordinates being passed are correct. Hopefully someone has a keen eye and a solution to my problem. A sample code is as follows: { Header_Font = new Font("Tahoma", 20); Header_Font_2 = new Font("Tahoma", 10); Line_Font = new Font("Tahoma", 10); Body_Font = new Font("Tahoma", 15); Footer_Font = new Font("Tahoma", 10); float y = 10; Header_Title = "HOST"; //----------TITLE--------------------------------------------- //HEADER. HEADER ALIGNMENTS StringFormat sf =(StringFormat)StringFormat.GenericTypographic.Clone(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisWord; //1st Placement ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); //SIZE MEASUREMENT SizeF fs = ev.Graphics.MeasureString(Header_Title, Header_Font, Int32.MaxValue, StringFormat.GenericTypographic); //UPDATE PLACEMENT y += Convert.ToInt32(fs.Height); //2nd Placement ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); //SIZE MEASUREMENT fs = ev.Graphics.MeasureString(Header_Title, Header_Font, Int32.MaxValue, StringFormat.GenericTypographic); //UPDATE PLACEMENT y += Convert.ToInt32(fs.Height); //3rd Placement ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); } Thank you all in advance. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Printing. DrawLine/DrawString. C# [WIN] "MikeY" <mikesinfo@xxxxxx> wrote in message news:OFkWFEqFKHA.4316@xxxxxx Quote: > Hi Everyone, > > My problem is this: I'm having a hard time lining up Graphics.DrawString > and Graphics.DrawLine. In that I'm not being able to control the > placement of the lines being drawn to my printer after the header. The "y" > co-ordinates are all fine and dandy with DrawString (Text), but they get > messed up with DrawLine and not being placed exactly co-ordinates where I > want them to be drawn. Co-ordinates being passed are correct. Hopefully > someone has a keen eye and a solution to my problem. A sample code is as > follows: > > { > Header_Font = new Font("Tahoma", 20); > Header_Font_2 = new Font("Tahoma", 10); > Line_Font = new Font("Tahoma", 10); > Body_Font = new Font("Tahoma", 15); > Footer_Font = new Font("Tahoma", 10); > float y = 10; > Header_Title = "HOST"; > //----------TITLE--------------------------------------------- > //HEADER. HEADER ALIGNMENTS > StringFormat sf =(StringFormat)StringFormat.GenericTypographic.Clone(); > sf.Alignment = StringAlignment.Center; > sf.LineAlignment = StringAlignment.Center; > sf.Trimming = StringTrimming.EllipsisWord; > > > //1st Placement > ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new > RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); > ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); > > //SIZE MEASUREMENT > SizeF fs = ev.Graphics.MeasureString(Header_Title, Header_Font, > Int32.MaxValue, StringFormat.GenericTypographic); > > //UPDATE PLACEMENT > y += Convert.ToInt32(fs.Height); > > //2nd Placement > ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new > RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); > ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); > > //SIZE MEASUREMENT > fs = ev.Graphics.MeasureString(Header_Title, Header_Font, Int32.MaxValue, > StringFormat.GenericTypographic); > > //UPDATE PLACEMENT > y += Convert.ToInt32(fs.Height); > > //3rd Placement > ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new > RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); > ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); > } > > > Thank you all in advance. > > horizontal (x) positioning. Try using a fixed font vs. a proportional font and see if that helps. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Printing. DrawLine/DrawString. C# [WIN] Hi Pvd, Thank you for your response. The "x" horizontal, is prefectly fine for both. The "y" vertical positioning is fine for the DrawString, but gets messed up with the DrawLine. I think that it might be that they are taking the co-ordinances in different formats, I'm not sure. I've been trying to find that out, and if so, how do I unify them (convert them to the same input). I concluded this from the line placements being alter with new "y" inputs and everything else being exactly the same. The causes the "y" DrawString placements to always be where the should be placed, but not so for the "y" placements of the DrawLine inputs. It seems with the DrawLine being drawn above the actual spot of where it should be drawn. hmmm. That is the only thing I can think of as to where the problem is arising. If I'm making sense. MikeY "PvdG42" <pvdg@xxxxxx> wrote in message news:uyQ$E4sFKHA.5780@xxxxxx Quote: > > "MikeY" <mikesinfo@xxxxxx> wrote in message > news:OFkWFEqFKHA.4316@xxxxxx Quote: >> Hi Everyone, >> >> My problem is this: I'm having a hard time lining up Graphics.DrawString >> and Graphics.DrawLine. In that I'm not being able to control the >> placement of the lines being drawn to my printer after the header. The >> "y" co-ordinates are all fine and dandy with DrawString (Text), but they >> get messed up with DrawLine and not being placed exactly co-ordinates >> where I want them to be drawn. Co-ordinates being passed are correct. >> Hopefully someone has a keen eye and a solution to my problem. A sample >> code is as follows: >> >> { >> Header_Font = new Font("Tahoma", 20); >> Header_Font_2 = new Font("Tahoma", 10); >> Line_Font = new Font("Tahoma", 10); >> Body_Font = new Font("Tahoma", 15); >> Footer_Font = new Font("Tahoma", 10); >> float y = 10; >> Header_Title = "HOST"; >> //----------TITLE--------------------------------------------- >> //HEADER. HEADER ALIGNMENTS >> StringFormat sf =(StringFormat)StringFormat.GenericTypographic.Clone(); >> sf.Alignment = StringAlignment.Center; >> sf.LineAlignment = StringAlignment.Center; >> sf.Trimming = StringTrimming.EllipsisWord; >> >> >> //1st Placement >> ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new >> RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); >> ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); >> >> //SIZE MEASUREMENT >> SizeF fs = ev.Graphics.MeasureString(Header_Title, Header_Font, >> Int32.MaxValue, StringFormat.GenericTypographic); >> >> //UPDATE PLACEMENT >> y += Convert.ToInt32(fs.Height); >> >> //2nd Placement >> ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new >> RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); >> ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); >> >> //SIZE MEASUREMENT >> fs = ev.Graphics.MeasureString(Header_Title, Header_Font, Int32.MaxValue, >> StringFormat.GenericTypographic); >> >> //UPDATE PLACEMENT >> y += Convert.ToInt32(fs.Height); >> >> //3rd Placement >> ev.Graphics.DrawString(Header_Title, Header_Font, Brushes.Black,new >> RectangleF(ev.PageBounds.Left,y,ev.PageBounds.Right - 400,y),sf); >> ev.Graphics.DrawLine(Pens.Red,ev.PageBounds.Left,y,ev.PageBounds.Right,y); >> } >> >> >> Thank you all in advance. >> >> > horizontal (x) positioning. Try using a fixed font vs. a proportional font > and see if that helps. > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| printing a file created by the windows printing dialog (print to f | PowerShell | |||
| HP web printing with IE8 | Vista General | |||
| drawstring disappears? | .NET General | |||
| printing | Vista print fax & scan | |||
| ps and printing | PowerShell | |||