473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Printing / turning 90 degrees

How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.

Many thanks,
Patrick.

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public Printing()
{
doPrinting();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
// Print the file.
public void doPrinting()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}
Nov 15 '05 #1
5 10043
Patrick,
For the items you want to print rotated do the following:
System.Drawing.Drawing2D.GraphicsState svd = ev.Graphics.Save();
// then get the x,y location of the top/left of the string you want to
print
// and transform to the new locationi
ev.Graphics.TranslateTransform(x, y, MatrixOrder.Prepend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.RotateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Restore(svd); // and restore the saved state
Note that you will be back at the location you started at so you may need to
do some
measuring/repositioning for the next string to draw.

Ron Allen
"Patrick De Ridder" <00@00.00> wrote in message
news:10**************@evisp-news-01.ops.asmr-01.energis-idc.net...
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.

Many thanks,
Patrick.

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public Printing()
{
doPrinting();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
// Print the file.
public void doPrinting()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}

Nov 15 '05 #2
Thanks Ron,
do I understand that I need to know the coordinates of the strings at zero
degrees
to be able to turn them ninety degrees? (I want to print envelopes).

Is there no simple(r) way to modify the (MSDN) code (below)?

Patrick.
"Ron Allen" <rallen@_nospam_src-us.com> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing.Drawing2D.GraphicsState svd = ev.Graphics.Save();
// then get the x,y location of the top/left of the string you want to
print
// and transform to the new locationi
ev.Graphics.TranslateTransform(x, y, MatrixOrder.Prepend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.RotateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Restore(svd); // and restore the saved state
Note that you will be back at the location you started at so you may need to do some
measuring/repositioning for the next string to draw.

Ron Allen
"Patrick De Ridder" <00@00.00> wrote in message
news:10**************@evisp-news-01.ops.asmr-01.energis-idc.net...
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.

Many thanks,
Patrick.

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public Printing()
{
doPrinting();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) {
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
// Print the file.
public void doPrinting()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}


Nov 15 '05 #3
How do I integrate your code into that which I posted?
Patrick.
"Ron Allen" <rallen@_nospam_src-us.com> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing.Drawing2D.GraphicsState svd = ev.Graphics.Save();
// then get the x,y location of the top/left of the string you want to
print
// and transform to the new locationi
ev.Graphics.TranslateTransform(x, y, MatrixOrder.Prepend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.RotateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Restore(svd); // and restore the saved state
Note that you will be back at the location you started at so you may need to do some
measuring/repositioning for the next string to draw.

Ron Allen
"Patrick De Ridder" <00@00.00> wrote in message
news:10**************@evisp-news-01.ops.asmr-01.energis-idc.net...
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.

Many thanks,
Patrick.

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public Printing()
{
doPrinting();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) {
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
// Print the file.
public void doPrinting()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}


Nov 15 '05 #4
Patrick,
It depends on where you want the printed line/string to be rotated. Do
you want everything rotated as in landscape printing? If so, it may just be
easier to set the PageSettings.Landscape property to true for your pages (in
OnQueryPageSettings is where I normally do this). This basically does the
rotation and the required translation for you.
You can do about the same thing by doing a Rotate(-90.0f) and then a
Translate by the width of the page (in portrait mode) to get the the
coordinate system aligned correctly. This should have your position at the
top/left of the drawing area In this case you don't need to save the state
of the Graphics objects as you will be using the translated/rotated
coordinates throughout. You would put the Translate and Rotate before all
the other drawing statements.
To do just one line/string you need to know where you are going to start
the string so you can rotate just that part and then go back to using the
standard coordinate system.

Ron Allen

"Patrick De Ridder" <wn********@all.here> wrote in message
news:10***************@evisp-news-01.ops.asmr-01.energis-idc.net...
How do I integrate your code into that which I posted?
Patrick.
"Ron Allen" <rallen@_nospam_src-us.com> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing.Drawing2D.GraphicsState svd = ev.Graphics.Save();
// then get the x,y location of the top/left of the string you want to
print
// and transform to the new locationi
ev.Graphics.TranslateTransform(x, y, MatrixOrder.Prepend);
// rotate 90 degrees clockwise -- assuming that you want text going up :=)
ev.Graphics.RotateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Restore(svd); // and restore the saved state
Note that you will be back at the location you started at so you may
need to
do some
measuring/repositioning for the next string to draw.

Ron Allen
"Patrick De Ridder" <00@00.00> wrote in message
news:10**************@evisp-news-01.ops.asmr-01.energis-idc.net...
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.

Many thanks,
Patrick.

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;
public Printing()
{
doPrinting();
}
// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line=null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamToPrint.ReadLine()) !=

null)) {
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString (line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
// Print the file.
public void doPrinting()
{
try
{
streamToPrint = new StreamReader (filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}



Nov 15 '05 #5
Your reference to

DefaultPageSettings.Landscape

has lead me on to an example in MSDN, which I expect is going
resolve my printing query.

I need the rotation business for envelope printing in an app.

(ad interim I am having the HP printer swing the image around,
for which it only needs a couple of special characters)

Thank you.

Patrick.
"Ron Allen" <rallen@_nospam_src-us.com> wrote in message
news:uR**************@TK2MSFTNGP11.phx.gbl...
Patrick,
It depends on where you want the printed line/string to be rotated. Do you want everything rotated as in landscape printing? If so, it may just be easier to set the PageSettings.Landscape property to true for your pages (in OnQueryPageSettings is where I normally do this). This basically does the
rotation and the required translation for you.
You can do about the same thing by doing a Rotate(-90.0f) and then a
Translate by the width of the page (in portrait mode) to get the the
coordinate system aligned correctly. This should have your position at the top/left of the drawing area In this case you don't need to save the state of the Graphics objects as you will be using the translated/rotated
coordinates throughout. You would put the Translate and Rotate before all
the other drawing statements.
To do just one line/string you need to know where you are going to start the string so you can rotate just that part and then go back to using the
standard coordinate system.

Ron Allen

"Patrick De Ridder" <wn********@all.here> wrote in message
news:10***************@evisp-news-01.ops.asmr-01.energis-idc.net...
How do I integrate your code into that which I posted?
Patrick.
"Ron Allen" <rallen@_nospam_src-us.com> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing.Drawing2D.GraphicsState svd = ev.Graphics.Save();
// then get the x,y location of the top/left of the string you want
to
print
// and transform to the new locationi
ev.Graphics.TranslateTransform(x, y, MatrixOrder.Prepend);
// rotate 90 degrees clockwise -- assuming that you want text
going
up :=)
ev.Graphics.RotateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Restore(svd); // and restore the saved state
Note that you will be back at the location you started at so you may

need
to
do some
measuring/repositioning for the next string to draw.

Ron Allen
"Patrick De Ridder" <00@00.00> wrote in message
news:10**************@evisp-news-01.ops.asmr-01.energis-idc.net...
> How can I turn what I want to print 90 degrees using the logic

below? > Please tell me the code with which to make the modification.
>
> Many thanks,
> Patrick.
>
> using System.ComponentModel;
> using System.Drawing;
> using System.Drawing.Printing;
> using System.IO;
> using System.Windows.Forms;
>
> public class Printing
> {
> private Font printFont;
> private StreamReader streamToPrint;
> static string filePath;
> public Printing()
> {
> doPrinting();
> }
> // The PrintPage event is raised for each page to be printed.
> private void pd_PrintPage(object sender, PrintPageEventArgs ev)
> {
> float linesPerPage = 0;
> float yPos = 0;
> int count = 0;
> float leftMargin = ev.MarginBounds.Left;
> float topMargin = ev.MarginBounds.Top;
> string line=null;
> // Calculate the number of lines per page.
> linesPerPage = ev.MarginBounds.Height /
> printFont.GetHeight(ev.Graphics) ;
> // Iterate over the file, printing each line.
> while (count < linesPerPage && ((line=streamToPrint.ReadLine()) !=

null))
> {
> yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
> ev.Graphics.DrawString (line, printFont, Brushes.Black,
> leftMargin, yPos, new StringFormat());
> count++;
> }
> // If more lines exist, print another page.
> if (line != null)
> ev.HasMorePages = true;
> else
> ev.HasMorePages = false;
> }
> // Print the file.
> public void doPrinting()
> {
> try
> {
> streamToPrint = new StreamReader (filePath);
> try
> {
> printFont = new Font("Arial", 10);
> PrintDocument pd = new PrintDocument();
> pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
> // Print the document.
> pd.Print();
> }
> finally
> {
> streamToPrint.Close() ;
> }
> }
> catch
> {
> }
> }
> public static void send()
> {
> string arg = "temp.txt";
> filePath = arg;
> new Printing();
> }
> }
>
>



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Darcy Kahle | last post by:
I am trying to do some advanced printing in python using the win32ui module, and have run into an issue. I need to print a page landscape. As I could not determine how to specify the orientation...
20
by: Jeff Thies | last post by:
Is it possible to set the Math functions to use degrees instead of radians? I'm working out some astronomical calculations and everything is in degrees. All those conversions are driving me a...
6
by: Craig Parsons | last post by:
Folks, I have an image of a circle, which I am trying to straighten out into a flat line. I am essentially wanting to look at the image, and read a straight line from the centre, and then plot...
3
by: Tom McL. | last post by:
I have a program that produces a calendar which I would like to print at the bottom of a page so I can place a picture at the top. I use the following code to print the calendar:
5
by: Lance | last post by:
Hi all, Below is a funtion that converts a Lat or Lon coordinate (as a Double) to a string of Degrees, Minutes and Seconds. It's based on an MS Exmaple for VBA found here...
8
by: Steve Macleod | last post by:
Hi, I was wondering if anyone had a solution for printing HTML elements (especially style elements). I do not wish to make any changes to the page, other than in the <css media="print"block. I can...
3
by: Jlcarroll | last post by:
Hi, I am building a web page.and have a simple javascript menu... I call the javascript menu within a div block that my print sytlesheet has set as a display: none;, well all the content in that...
0
by: Tony | last post by:
I am printing tickets with star tsp700 (743c) on the LPT1 with VB.NET program (I olso use C#). I use OCX control of STAR company. If I turn off printer or unplug cable, program for printing is...
0
by: JDWRIGHT | last post by:
Could anyone explain printer coordinates as they relate to printing via the API? More specifically, how do I set the scale on a page via an API call? Currently, using "printer.line" to draw lines...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.