|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 268
|
[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? |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
Una domanda: per stampare intendi a video o su una stampante (ovvero creare un report ?)
Poi: che versione di visual studio stai utilizzando ?
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 268
|
Stampare con la stampante
Comunque la versione è la 2010 |
|
|
|
|
|
#4 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 268
|
up
|
|
|
|
|
|
#5 |
|
Bannato
Iscritto dal: Nov 2008
Messaggi: 136
|
Dai un'occhiata a questi link
http://msdn.microsoft.com/it-it/libr...2d(VS.80).aspx http://msdn.microsoft.com/it-it/libr...v=VS.100).aspx http://msdn.microsoft.com/it-it/libr...30(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 |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
|
#7 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 268
|
Ok grazie ragazzi in qualche modo ho risolto
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Feb 2003
Città: Stockholm (SE)
Messaggi: 1343
|
|
|
|
|
|
|
#9 |
|
Member
Iscritto dal: Jul 2009
Messaggi: 268
|
Codice:
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();
}
}
}
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 17:34.




















