e.Graphics.DrawString

T

Tony Johansson

Hello!

If I use the DrawString below with object of StringFormat as the last object
it works good.
If I instead remove object StringFormat below as the last object of
DrawString I get some rows that are not printed correctly.
It's look like when toner is too low for the printer.This is only for some
rows.
Can somebody explain why this happens?
What kind of StringFormat is used when this parameter is missing?


private void printPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
....
....
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float yPos = 0;
Font printFont = new Font("Arial", 12);
yPos = topMargin + printFont.GetHeight(e.Graphics);
e.HasMorePages = false;
e.Graphics.DrawString(data.ToString(), printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
}
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello!

If I use the DrawString below with object of StringFormat as the last object
it works good.
If I instead remove object StringFormat below as the last object of
DrawString I get some rows that are not printed correctly.
It's look like when toner is too low for the printer.This is only for some
rows.
Can somebody explain why this happens?
What kind of StringFormat is used when this parameter is missing?

private void printPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
...
...
float leftMargin = e.MarginBounds.Left;
float topMargin  = e.MarginBounds.Top;
float yPos = 0;
Font printFont = new Font("Arial", 12);
yPos = topMargin + printFont.GetHeight(e.Graphics);
e.HasMorePages = false;
e.Graphics.DrawString(data.ToString(), printFont, Brushes.Black,
                                    leftMargin, yPos, new StringFormat());



}- Hide quoted text -

- Show quoted text -

Hi,

Take alook at what the StringFormat provides.
IMO you are just creating the default one, and I'm of the opinion that
all the others overrides should use it as well.

Are you using 2008? if so you can trace inside teh framework and see
what is the differences between the different overloads versions.
 
T

Tony Johansson

Hello!

I'm using VS05.

So do you mean it's no point using this one with new StringFormat at the end
"Graphics.DrawString(data.ToString(), printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());"
because if I use this one without new StringFormat at the end
Graphics.DrawString(data.ToString(), printFont, Brushes.Black,
leftMargin, yPos);
the .NET framework will use the default which is the one with new
StringFormat.

//Tony




"Ignacio Machin ( .NET/ C# MVP )" <[email protected]> skrev i
meddelandet
Hello!

If I use the DrawString below with object of StringFormat as the last
object
it works good.
If I instead remove object StringFormat below as the last object of
DrawString I get some rows that are not printed correctly.
It's look like when toner is too low for the printer.This is only for some
rows.
Can somebody explain why this happens?
What kind of StringFormat is used when this parameter is missing?

private void printPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
...
...
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float yPos = 0;
Font printFont = new Font("Arial", 12);
yPos = topMargin + printFont.GetHeight(e.Graphics);
e.HasMorePages = false;
e.Graphics.DrawString(data.ToString(), printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());



}- Hide quoted text -

- Show quoted text -

Hi,

Take alook at what the StringFormat provides.
IMO you are just creating the default one, and I'm of the opinion that
all the others overrides should use it as well.

Are you using 2008? if so you can trace inside teh framework and see
what is the differences between the different overloads versions.
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello!

I'm using VS05.

So do you mean it's no point using this one with new StringFormat at the end
"Graphics.DrawString(data.ToString(), printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());"
because if I use this one without new StringFormat at the end
Graphics.DrawString(data.ToString(), printFont, Brushes.Black,> leftMargin, yPos);

the .NET framework will use the default which is the one with new
StringFormat.

Well, common sense indicate that, BUT you should check the code to see
if it's really that way, if you see the list of overloads you see that
the one you are using is the one with all the parameters specified,
most of the time you implement this chain by doing something like

void method( string param1){
method( param1, new MyClass() );
}
void method( string param1, MyClass param2){
....
 
B

Ben Voigt [C++ MVP]

Ignacio said:
Hi,

Take alook at what the StringFormat provides.
IMO you are just creating the default one, and I'm of the opinion that
all the others overrides should use it as well.

Are you using 2008? if so you can trace inside teh framework and see
what is the differences between the different overloads versions.

You can do the same for any framework version using Roeder's Reflector.

It so happens that the last argument is defaulted to null, not new
StringFormat(). null is passed through p/invoke to the underlying GDI+
function GdipDrawString (6th argument) which, as far as I can tell, is not
documented.

The GDI+ object model Graphics::DrawString method is documented, but the
documentation there is very sparse, it doesn't even say that the format
parameter is optional.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top