Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Printing. DrawLine/DrawString. C# [WIN]

Reply
 
Old 08-06-2009   #1 (permalink)
MikeY


 
 

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 SpecsSystem Spec
Old 08-06-2009   #2 (permalink)
PvdG42


 
 

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.
>
>
You say vertical (y) positioning is OK, so I'll assume the issue is
horizontal (x) positioning. Try using a fixed font vs. a proportional font
and see if that helps.


My System SpecsSystem Spec
Old 08-07-2009   #3 (permalink)
MikeY


 
 

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.
>>
>>
> You say vertical (y) positioning is OK, so I'll assume the issue is
> horizontal (x) positioning. Try using a fixed font vs. a proportional font
> and see if that helps.
>
>

My System SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46