PC Review


Reply
Thread Tools Rate Thread

Code for using print handler

 
 
Allen
Guest
Posts: n/a
 
      4th Oct 2009
Hi everybody,

I need your help.

I use MS VS C++ 2008
Hi everybody,



I need your help.



The code below is good if I want to print a sketch. The book did not show
how to print a simple text 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 appreciate 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

pdoc->Print();



}

else

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

}



void PrintAPage(Object^ pSender, PrintPageEventArgs^ pe)

{









}



If I put the following code inside the empty function (PrintAPage)I will be
ablble to draw and print what I draw. But what I need is to print an
already written and saved simple text File.



Graphics* gr = pe->Graphics;
Pen* pen1 = new Pen(Color::Black);

// Draw the image
Bitmap* bmp = new Bitmap(S"ramp1.gif");
gr->DrawImage(bmp, 10,10);

for(int i=0; i<list->Count; i++)
{
Line* pl = dynamic_cast<Line*>(list->get_Item(i));
gr->DrawLine(pen1, pl->p1.X,pl->p1.Y, pl->p2.X,pl->p2.Y);
}



Hi everybody,



I need your help.



The code below is good if I want to print a sketch. The book did not show
how to print a simple text 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

pdoc->Print();



}

else

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

}



void PrintAPage(Object^ pSender, PrintPageEventArgs^ pe)

{









}



If I put the following code inside the empty function (PrintAPage)I will be
ablble to draw and print what I draw. But what I need is to print an
already written and saved simple text File.



Graphics* gr = pe->Graphics;
Pen* pen1 = new Pen(Color::Black);

// Draw the image
Bitmap* bmp = new Bitmap(S"ramp1.gif");
gr->DrawImage(bmp, 10,10);

for(int i=0; i<list->Count; i++)
{
Line* pl = dynamic_cast<Line*>(list->get_Item(i));
gr->DrawLine(pen1, pl->p1.X,pl->p1.Y, pl->p2.X,pl->p2.Y);
}



good if I want to print a sketch. The book did not show how to print a
simple text 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
pdoc->Print();

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

void PrintAPage(Object^ pSender, PrintPageEventArgs^ pe)
{




}

If I put the following code inside the empty function (PrintAPage)I will be
ablble to draw and print what I draw. But what I need is to print an
already written and saved simple text File.

Graphics* gr = pe->Graphics;
Pen* pen1 = new Pen(Color::Black);

// Draw the image
Bitmap* bmp = new Bitmap(S"ramp1.gif");
gr->DrawImage(bmp, 10,10);

for(int i=0; i<list->Count; i++)
{
Line* pl = dynamic_cast<Line*>(list->get_Item(i));
gr->DrawLine(pen1, pl->p1.X,pl->p1.Y, pl->p2.X,pl->p2.Y);
}



--
Thanks
Allen

 
Reply With Quote
 
 
 
 
Family Tree Mike
Guest
Posts: n/a
 
      4th Oct 2009
Allen wrote:
> Hi everybody,
>
> I need your help.
>
> I use MS VS C++ 2008
> Hi everybody,
>
>
> <cut>


This looks very similar to what you posted the other day on
microsoft.public.dotnet.general. You have an answer there, but to add
to that, here is an example to do what I believe you want:

http://msdn.microsoft.com/en-us/libr...tdocument.aspx

--
Mike
 
Reply With Quote
 
Allen
Guest
Posts: n/a
 
      6th Oct 2009
Thanks Mike,

Now; I am going somewhere.

--
Thanks
Allen
"Family Tree Mike" <(E-Mail Removed)> wrote in message
news:eK$(E-Mail Removed)...
> Allen wrote:
>> Hi everybody,
>>
>> I need your help.
>>
>> I use MS VS C++ 2008
>> Hi everybody,
>>
>>
>> <cut>

>
> This looks very similar to what you posted the other day on
> microsoft.public.dotnet.general. You have an answer there, but to add to
> that, here is an example to do what I believe you want:
>
> http://msdn.microsoft.com/en-us/libr...tdocument.aspx
>
> --
> Mike


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use print handler to pring a file? Allen Microsoft ASP .NET 3 4th Oct 2009 12:35 PM
Event handler code creater for C# =?Utf-8?B?bXIgcGVhbnV0?= Microsoft C# .NET 1 12th Sep 2007 10:57 PM
How can I debug event handler code in the IDE? =?Utf-8?B?RGF2ZSBKZW5raW5z?= Microsoft Powerpoint 8 12th Aug 2007 02:49 AM
Determinig if a handler exists from code Doug Microsoft VB .NET 3 31st Aug 2004 08:12 PM
Message Box in An event handler code =?Utf-8?B?QW5pbA==?= Microsoft C# .NET 2 24th Jan 2004 08:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:28 AM.