How can I use print handler to pring a file?



How can I use print handler to pring a file?


Hi everybody,

I need your help.

The code below came from a book which teaches how to print a sketch. The
book did not show how to print a file. Right now if I run this program (as
is)it will show the printer dialog box. If I click OK (to print), the
printer will print an empty paper. How can I use this code to print a file

I would apprciate it if you could help.

private: System::Void printToolStripMenuItem_Click(System::Object ^ sender,
System::EventArgs ^ e)
// The PrintDocument holds the settings
PrintDocument^ pdoc = gcnew PrintDocument();

// Create a dialog and attach it to the document
PrintDialog^ pd = gcnew PrintDialog();

pd->Document = pdoc;

// Show the dialog
if (pd->ShowDialog() == System::Windows::Forms:ialogResult::OK)

// Add the page handler

pdoc->PrintPage += gcnew PrintPageEventHandler(this,&Form1::printAPage);
// Print the page

MessageBox::Show("Print cancelled", "Information");

void PrintAPage(Object^ pSender, PrintPageEventArgs^ pe)



Can you give me an address for a Windows programming group?

I would try a group such as :


Also the link I provided earlier shows how to print a file assuming each
line is small enought to fit on a single line. It uses C# but it should be
easy to convert to C++/CLI.

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