View Full Version : [C#] Stampare in Visual Form
Salve,
avrei bisogno di stampare il contenuto di una textBox in una Visual Form in C#.
Sapete darmi una mano?
RaouL_BennetH
02-10-2010, 22:24
Una domanda: per stampare intendi a video o su una stampante (ovvero creare un report ?)
Poi: che versione di visual studio stai utilizzando ?
Stampare con la stampante :)
Comunque la versione è la 2010
Dai un'occhiata a questi link
http://msdn.microsoft.com/it-it/library/cwbe712d(VS.80).aspx
http://msdn.microsoft.com/it-it/library/system.drawing.printing.printdocument(v=VS.100).aspx
http://msdn.microsoft.com/it-it/library/aa287530(VS.71).aspx
Consiglio: guarda sempre sulla msdn, trovi tutto ciò che ti serve in italiano, se proprio ti va male c'è la guida in inglese ma non manca mai nulla
RaouL_BennetH
05-10-2010, 09:34
prova anche qui:
http://www.dreamincode.net/forums/topic/50924-use-a-print-dialog-box-to-print-contents-of-a-textbox/
Ok grazie ragazzi in qualche modo ho risolto :)
Kralizek
06-10-2010, 15:56
Ok grazie ragazzi in qualche modo ho risolto :)
una nota da lasciare ai posteri?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string stringToPrint;
private void ReadFile()
{
string docName = "testPage.txt";
string docPath = @"C:\";
printDocument1.DocumentName = docName;
using (FileStream stream = new FileStream(docPath + docName, FileMode.Open))
using (StreamReader reader = new StreamReader(stream))
{
stringToPrint = reader.ReadToEnd();
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
int charactersOnPage = 0;
int linesPerPage = 0;
// Sets the value of charactersOnPage to the number of characters
// of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, this.Font,
e.MarginBounds.Size, StringFormat.GenericTypographic,
out charactersOnPage, out linesPerPage);
// Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,
e.MarginBounds, StringFormat.GenericTypographic);
// Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage);
// Check to see if more pages are to be printed.
e.HasMorePages = (stringToPrint.Length > 0);
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ReadFile();
printDocument1.Print();
}
}
}
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.