M
MikeY
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 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.