473,699 Members | 2,900 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 10139
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
3015
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 I need it to go. I tried to use the hDC.SetWorldTransform(0, -1, 1, 0, 0, 0) command to rotate...
20
4206
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
2981
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 determine how many pixels wide I should read, in order not to miss anything out? IE: If I rotate it 1...
3
1260
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
6614
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 ConvertDegrees(ByVal DecimalDegrees As Double) As String Dim Degrees As Int32 = 0
8
17740
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
4226
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
1720
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 at the end, he write to DB that transaction. Problem is when printer is on, but paper is out....
0
2396
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 but the rotated text is all bunched up in the upper left of the page. It seems the printer scale...
0
8633
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9055
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8947
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
6552
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4392
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.