oshnood
سه شنبه 18 اسفند 1388, 14:21 عصر
دوستان چطور ميشه براي چاپ سند ورد در سي شارپ از كنترلPrint Dialog استفاده كرد؟؟؟؟؟؟؟؟:گیج::گیج:
oshnood
سه شنبه 18 اسفند 1388, 16:06 عصر
دوستان چطور ميشه براي چاپ سند ورد در سي شارپ از كنترلPrint Dialog استفاده كرد؟؟؟؟؟؟؟؟:گیج::گیج:
اين كد منه.تا يه جاهاييش درسته اما متن رو عجيب غريب چاپ ميكنه.نميدونم اشكال از متن فارسيه يا...
لطفا راهنمايي كنيد
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
namespace Azmoon
{
public partial class PrintForm : Form
{
private StreamReader objstreamtoprint;
private Font objPrintFont;
private string filename;
public PrintForm()
{
InitializeComponent();
}
private void PrintForm_Load(object sender, EventArgs e)
{
filename = Application.StartupPath + "\\filename.doc";
button1.Cursor = Cursors.Hand;
button2.Cursor = Cursors.Hand;
}
private void button1_Click(object sender, EventArgs e)
{
PrintDocument objprintdocument = new PrintDocument();
objprintdocument.DocumentName = "چاپ";
printDialog1.Document = objprintdocument;
if (printDialog1.ShowDialog() == DialogResult.OK)
{
objstreamtoprint = new StreamReader(filename);
objPrintFont=new Font("Tahoma",10);
objprintdocument.PrinterSettings = printDialog1.PrinterSettings;
objprintdocument.PrintPage += new PrintPageEventHandler(prtpage);
objprintdocument.Print();
objstreamtoprint.Close();
objstreamtoprint = null;
}
}
private void prtpage(object sender, PrintPageEventArgs e)
{
float sngLinesPerpage=0;
float sngVerticalPosition=0;
int intLineCount=0;
float sngLeftMargin=e.MarginBounds.Left;
float sngTopMargin=e.MarginBounds.Top;
string strLine;
sngLinesPerpage=e.MarginBounds.Height;
objPrintFont.GetHeight(e.Graphics);
strLine=objstreamtoprint.ReadLine();
while((intLineCount<sngLinesPerpage)&&(strLine!=null))
{
sngVerticalPosition = sngTopMargin + (intLineCount * objPrintFont.GetHeight(e.Graphics));
e.Graphics.DrawString(strLine, objPrintFont, Brushes.Black, sngLeftMargin, sngVerticalPosition, new StringFormat());
intLineCount = intLineCount + 1;
if (intLineCount < sngLinesPerpage)
{
strLine = objstreamtoprint.ReadLine();
}
}
if (strLine!=null)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;}
}
}
}
vBulletin® v4.0.8, Copyright ©2000-1391, Jelsoft Enterprises Ltd.