Print question

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();
}
}
}
 
J

Jeff Johnson

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

No, because that's not what these groups are for. If you have a specific
question, ask it. But don't just post code and say "Fix it."
 
D

Dom

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();
        }
    }



}- Hide quoted text -

- Show quoted text -

What about it doesn't work? It works for me.
 
Z

zach

I have looked all over the place for the answer, as I pointed
out in my post, so don't ride sich a high horse.
 
Z

zach

Dom said:
On Dec 1, 8:16 am, "Boreas" <[email protected]> wrote:
What about it doesn't work? It works for me.

I couldn't get it to do some printing, and I haven't a clue
how to put it right. The problem seems to be how to get the
print dialogue to accept the document offered to it for
printing. It would seem to need other or additional code.
 
J

Jeff Johnson

I have looked all over the place for the answer, as I pointed
out in my post, so don't ride sich a high horse.

The answer TO WHAT? You plopped down some code and basically said, "Read
this, figure out what it's supposed to do, and then make it do so." No
effort on your part to describe the problem = no effort on my part to solve
the problem, and I assure you I'm not the only one around here who feels
that way. "More flies with honey," blah blah blah.
 
B

Boreas

Jeff Johnson said:
The answer TO WHAT? You plopped down some code and basically said, "Read
this, figure out what it's supposed to do, and then make it do so." No
effort on your part to describe the problem = no effort on my part to
solve the problem, and I assure you I'm not the only one around here who
feels that way. "More flies with honey," blah blah blah.
Pig.
 
D

Dom


That response should get you off the list, but one more try.

"I couldn't get it to do some printing, and I haven't a clue
how to put it right. The problem seems to be how to get the
print dialogue to accept the document offered to it for
printing."

The PrinDialogue does not accept a file. It allows the user to choose
a printer. You must tell the print dialogue the PrintDocument you
want printed. Like this:

printDlg.Document = printDoc;

But why are you bothering to copy the file into a text string? This
is just incomplete code, and you aren't allowing anyone to help you.
Go back to the blabla.
 
B

Boreas

Dom said:
But why are you bothering to copy the file into a text string? This
is just incomplete code, and you aren't allowing anyone to help you.
Go back to the blabla.

Actually I use a print utility that I wrote in the past, which works
perfectly well in a number of applications. But the printing per se is being
done by means of code. I was hoping to replace that code. I have looked at
verious examples on the Internet, and find those examples wanting in
clarity. If I could better explain my problem, I would not be having that
problem, and I would not be meeting with hostility due to the fact that I am
unable to explain my problem better. I am a believer in the saying that help
is defined by the one in need of help, and not by the helper and therefore
take offence to some of the response I have been getting.
 
R

Rick Lones

Boreas said:
Actually I use a print utility that I wrote in the past, which works
perfectly well in a number of applications. But the printing per se is
being done by means of code. I was hoping to replace that code. I have
looked at verious examples on the Internet, and find those examples
wanting in clarity. If I could better explain my problem, I would not be
having that problem, and I would not be meeting with hostility due to
the fact that I am unable to explain my problem better. I am a believer
in the saying that help is defined by the one in need of help, and not
by the helper and therefore take offence to some of the response I have
been getting.

Possibly that saying makes some sense if you are talking about help for which
you have prepaid a vendor. You can be as vague and demanding as you like but
the support people will still usually feel that they must try to figure out WTF
your actual problem is even if you are not meeting them even halfway.

HTH,
-rick-
 
B

Boreas

Rick Lones said:
Possibly that saying makes some sense if you are talking about help for
which you have prepaid a vendor. You can be as vague and demanding as you
like but the support people will still usually feel that they must try to
figure out WTF your actual problem is even if you are not meeting them
even halfway.
In a situation where help is given for free, the helper, who isn't satisfied
with the effort the person ("Person") asking for help is taking, to
formulate his/her problem a bit better, can simply not respond. Person might
not know what his/her problem really is, and is therefore be unable to state
his/her problem succinctly: Person should not be punished for that with
hostility. Person might be helped in the first place, by asking Person a few
questions, to enable Person to state his/her problem more clearly. So I
disagree with the position you are taking.
 
B

Boreas

Peter Duniho said:
That's one option, yes. It's the choice I took when I saw your strikingly
vague question. But then, I have past experience with others who
similarly fail to understand what constitutes a respectful and useful
question and who take great offense at the merest suggestion that they
should have taken more care with phrasing their question. I decided this
time to try to avoid that mess.
etc.

Pete, thank you kindly.
 
R

Rick Lones

Boreas said:
In a situation where help is given for free, the helper, who isn't
satisfied with the effort the person ("Person") asking for help is
taking, to formulate his/her problem a bit better, can simply not
respond. Person might not know what his/her problem really is, and is
therefore be unable to state his/her problem succinctly: Person should
not be punished for that with hostility. Person might be helped in the
first place, by asking Person a few questions, to enable Person to state
his/her problem more clearly. So I disagree with the position you are
taking.

Hostility? Punishment? I must have missed that post. What happened - did
someone call you a pig or something?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top