I want to print my TextBox
and here is my code:
private void MenuItemPrint()
{
if (FileName != "")
{
PrintDocument document = new PrintDocument();
document.PrinterSettings.PrintFileName = FileName;
document.Print();
}
}
and it doesn't work. What should I do?
Try This:
private void MenuItemPrint()
{
if (!FileName.Trim().Equals(""))
{
using(PrintDocument pd = new PrintDocument())
{
using(PrintDialog printDialog=new PrintDialog())
{
if(printDialog.ShowDialog()==DialogResult.Yes)
{
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
}
}
}
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawString(FileName, new Font("Arial", 10), Brushes.Black,
ev.MarginBounds.Left, 0, new StringFormat());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With