PDA

View Full Version : سوال: یه کد برای Redo میخام



JustAcMilan
سه شنبه 08 فروردین 1391, 21:25 عصر
من یه نت پد جمه و جور نوشتم اما برای یو چیز مشکل دارم
یکی کد برای redo کردنه
یکیم برای پرینت گرفتن
من سورسشو ضمیمه میکنم ممنون میشم اگه اساتید یه نیگا بش بندازن

asadegha
سه شنبه 08 فروردین 1391, 23:01 عصر
textbox رو بردار بجاش richtextbox بزار



richTextBox1.Redo();
richTextBox1.Undo();

JustAcMilan
چهارشنبه 09 فروردین 1391, 14:52 عصر
ممنون که کمک کردی اما برا پرینت چیکار کنم
textbox رو بردار بجاش richtextbox بزار



richTextBox1.Redo();
richTextBox1.Undo();

vof.ir
پنج شنبه 10 فروردین 1391, 17:09 عصر
برای پرینت دیگه کار به این راحتی نیست، اگر میخواهید محتوای یک تکست باکس را پرینت بگیرید، فکر کنم باید یا کنترل شما این امکان را داشته باشه، یا اینکه به صورت دستی خودتون کاری کنید که محتوای درون تکست باکس تبدیل به یک فایل بشه و به نحوی اون فایل را پرینت بگیرید.

samadblaj
پنج شنبه 10 فروردین 1391, 18:13 عصر
باید با استفاده از کلاس Stream Reader این کارو کنید.
حالا کد زیر رو داشته باشید، کارتون با این راه میفته فقط نیفتاد بگید تا یه پروژه داشتم براتون پیداش کنم.




using System.IO;
using System.Drawing.Printing;

private string strFileName;
private StreamReader objStreamToPrint;
private Font objPrintFont;

private void btnPrint_Click(object sender, EventArgs e)
{
// Declare an object for the PrintDocument class
PrintDocument objPrintDocument = new PrintDocument();
// Set the DocumentName property
objPrintDocument.DocumentName = "Text File Print
Demo";
// Set the PrintDialog properties
printDialog1.AllowPrintToFile = false;
printDialog1.AllowSelection = false;
printDialog1.AllowSomePages = false;
// Set the Document property for
// the objPrintDocument object
printDialog1.Document = objPrintDocument;
// Show the Print dialog
if (printDialog1.ShowDialog() == DialogResult.OK)
{
// then set the StreamReader object to
// the file name in the strFileName variable
objStreamToPrint = new StreamReader(strFileName);
// Set the printer font
objPrintFont = new Font("Arial", 10);
// Set the PrinterSettings property of the
// objPrintDocument Object to the
// PrinterSettings property returned from the
// PrintDialog control
objPrintDocument.PrinterSettings =
printDialog1.PrinterSettings;
// Add an event handler for the PrintPage event of
// the objPrintDocument object
objPrintDocument.PrintPage +=
new PrintPageEventHandler(prtPage);
// Print the text file
objPrintDocument.Print();
// Clean up
objStreamToPrint.Close();
objStreamToPrint = null;
}


private void prtPage(object sender, PrintPageEventArgs e)
{
// Declare variables
float sngLinesPerpage = 0;
float sngVerticalPosition = 0;
int intLineCount = 0;
float sngLeftMargin = e.MarginBounds.Left;
float sngTopMargin = e.MarginBounds.Top;
string strLine;
// Work out the number of lines per page.
// Use the MarginBounds on the event to do this
sngLinesPerpage = e.MarginBounds.Height /
objPrintFont.GetHeight(e.Graphics);


// This assumes that a single line is not wider than
// the page width. Check intLineCount first so that we
// don’t read a line that we won’t print
strLine = objStreamToPrint.ReadLine();
while((intLineCount < sngLinesPerpage) &&
(strLine != null))
{
// Calculate the vertical position on the page
sngVerticalPosition = sngTopMargin +
(intLineCount * objPrintFont.GetHeight(e.Graphics));
// Pass a StringFormat to DrawString for the
// Print Preview control
e.Graphics.DrawString(strLine, objPrintFont,
Brushes.Black, sngLeftMargin,
sngVerticalPosition,
new StringFormat());
// Increment the line count
intLineCount = intLineCount + 1;
// If the line count is less than the lines per
// page then read another line of text
if (intLineCount < sngLinesPerpage)
{
strLine = objStreamToPrint.ReadLine();
}
}
// If we have more lines then print another page
if (strLine != null)
{
e.HasMorePages = true;
}
else
{
e.HasMorePages = false;
}
}