473,585 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Componen tModel;
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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) != null))
{
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}
Nov 15 '05 #1
5 10101
Patrick,
For the items you want to print rotated do the following:
System.Drawing. Drawing2D.Graph icsState svd = ev.Graphics.Sav e();
// 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.Tra nslateTransform (x, y, MatrixOrder.Pre pend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.Rot ateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Res tore(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.Componen tModel;
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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) != null))
{
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
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******** ******@TK2MSFTN GP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing. Drawing2D.Graph icsState svd = ev.Graphics.Sav e();
// 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.Tra nslateTransform (x, y, MatrixOrder.Pre pend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.Rot ateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Res tore(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.Componen tModel;
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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) != null)) {
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
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******** ******@TK2MSFTN GP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing. Drawing2D.Graph icsState svd = ev.Graphics.Sav e();
// 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.Tra nslateTransform (x, y, MatrixOrder.Pre pend);
// rotate 90 degrees clockwise -- assuming that you want text going up
:=)
ev.Graphics.Rot ateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Res tore(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.Componen tModel;
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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) != null)) {
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
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.La ndscape property to true for your pages (in
OnQueryPageSett ings 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******** ******@TK2MSFTN GP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing. Drawing2D.Graph icsState svd = ev.Graphics.Sav e();
// 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.Tra nslateTransform (x, y, MatrixOrder.Pre pend);
// rotate 90 degrees clockwise -- assuming that you want text going up :=)
ev.Graphics.Rot ateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Res tore(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.Componen tModel;
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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
// Iterate over the file, printing each line.
while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) !=

null)) {
yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
// Print the document.
pd.Print();
}
finally
{
streamToPrint.C lose() ;
}
}
catch
{
}
}
public static void send()
{
string arg = "temp.txt";
filePath = arg;
new Printing();
}
}



Nov 15 '05 #5
Your reference to

DefaultPageSett ings.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******** ******@TK2MSFTN GP11.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.La ndscape property to true for your pages (in OnQueryPageSett ings 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******** ******@TK2MSFTN GP10.phx.gbl...
Patrick,
For the items you want to print rotated do the following:
System.Drawing. Drawing2D.Graph icsState svd = ev.Graphics.Sav e();
// 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.Tra nslateTransform (x, y, MatrixOrder.Pre pend);
// rotate 90 degrees clockwise -- assuming that you want text
going
up :=)
ev.Graphics.Rot ateTransform(-90.0f);
// draw the text here using DrawString
ev.Graphics.Res tore(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.Componen tModel;
> 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(ob ject sender, PrintPageEventA rgs 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.GetHe ight(ev.Graphic s) ;
> // Iterate over the file, printing each line.
> while (count < linesPerPage && ((line=streamTo Print.ReadLine( )) !=

null))
> {
> yPos = topMargin + (count * printFont.GetHe ight(ev.Graphic s));
> ev.Graphics.Dra wString (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 PrintPageEventH andler(pd_Print Page);
> // Print the document.
> pd.Print();
> }
> finally
> {
> streamToPrint.C lose() ;
> }
> }
> 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
3005
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 of the printing, I arranged the graphic elements on the page the way it should be. When I got to printing text, it went across the page, not down as...
20
4189
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 bit crazy! Jeff
6
2978
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 this on a graph. Then I want to rotate the image 1 degree and read the next line down, if you see what I mean. My question is, how do I...
3
1255
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
6594
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 http://support.microsoft.com/?kbid=213449. Do you think this is this best way to go about it .NET, or could it be done more efficiently? ///// Private Function...
8
17736
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 use: select { border:1px solid #FFFFFF; } to get rid of the border, but dont know a way to get rid of the arrow
3
4220
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 block doesn't show up, EXCEPT the javascript is still getting run... <div class="menu"> <!--*****************These lines load in the
0
1709
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 blocked and it is ok (he will not mark this ticket as printed because program is on hold). After turning on the printer, program continue printing and...
0
2374
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 and the line work looks great on the page. I print rotated text (rotated 90 degrees) using an API to create a rotated font. The line work looks good...
0
7904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7835
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8195
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7947
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5707
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.