468,242 Members | 1,722 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

How can I move the margin to the left?

Ho can I move the margin to the left
by adding which code below?

Many thanks,
Adrian.

**************************

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

namespace PRL058
{
public class Printing
{
private Font printFont;
private StreamReader streamToPrint;
public static int reset;
int rule_param1;
int rule_param2;

public Printing()
{
getRuleParam();
doPrinting();
}

// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
#region settings
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
if (reset!=0)
topMargin = reset;
string line=null;
#endregion

#region make up the page
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
;
Pen blackPen = new Pen(Color.Black,.5F);

while (count < linesPerPage && ((line=streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

if(line.IndexOf("----") -1 )
{
ev.Graphics.DrawLine(blackPen,rule_param1, yPos, rule_param2, yPos);
count++;
continue;
}

if(line.IndexOf("====") -1 )
{
ev.Graphics.DrawLine(blackPen,rule_param1, yPos, rule_param2, yPos);
ev.Graphics.DrawLine(blackPen,rule_param1, yPos+2, rule_param2,
yPos+2);
count++;
continue;
}

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;
}

private void getRuleParam()
{
try
{
using(StreamReader sr = new StreamReader("RuleParam.txt"))
{
rule_param1 = Convert.ToInt32(sr.ReadLine());
rule_param2 = Convert.ToInt32(sr.ReadLine());
}
}
catch
{
rule_param1 = 750;
rule_param2 = 60;
}
}
#endregion

#region do printing
public void doPrinting()
{
try
{
streamToPrint = new StreamReader ("temporary.txt");
try
{
printFont = new Font("Courier New", 8);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.DefaultPageSettings.Landscape=true;
// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close() ;
}
}
catch
{
}
}
#endregion
}
}
Nov 22 '06 #1
0 1027

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by moocow | last post: by
reply views Thread by Helge | last post: by
10 posts views Thread by Alan Silver | last post: by
1 post views Thread by innivive | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.