B
Boreas
Could someone please add / change the lines to make this code work.
I have looked at all sorts of tutorial blabla, but cannot do it.
Please don't refer me to more blabla
Many thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;
namespace PrintExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string file_name = null;
using (OpenFileDialog dir = new OpenFileDialog())
{
dir.Title = "Open a file";
dir.InitialDirectory = "c:\\";
dir.Filter = "txt files (*.txt)|*.txt";
if (dir.ShowDialog() != DialogResult.OK) return;
file_name = dir.FileName;
}
string text = null;
using (StreamReader sr = new StreamReader(file_name))
{
string line = null;
while ((line = sr.ReadLine()) != null)
text += line;
}
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = text;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
printDlg.ShowDialog();
printDoc.Print();
}
}
}
I have looked at all sorts of tutorial blabla, but cannot do it.
Please don't refer me to more blabla
Many thanks
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.IO;
namespace PrintExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string file_name = null;
using (OpenFileDialog dir = new OpenFileDialog())
{
dir.Title = "Open a file";
dir.InitialDirectory = "c:\\";
dir.Filter = "txt files (*.txt)|*.txt";
if (dir.ShowDialog() != DialogResult.OK) return;
file_name = dir.FileName;
}
string text = null;
using (StreamReader sr = new StreamReader(file_name))
{
string line = null;
while ((line = sr.ReadLine()) != null)
text += line;
}
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = text;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
printDlg.ShowDialog();
printDoc.Print();
}
}
}