How to print a document when i press a button in Windows Forms Application?

I need help in making this code which was writen i VB, into C++ in windows Forms Application.

This is the following code:

private: System::Void printDocument1_PrintPage(System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e) {

e->Graphics->DrawString("Inköpslista", New Font("Ariel", 12, FontStyle->Regular, GraphicsUnit->Pixel), Brushes->Black, 25, 25);
e->Graphics->DrawString("___________", New Font("Ariel", 12, FontStyle->Regular, GraphicsUnit->Pixel), Brushes->Black, 25, 25);
e->Graphics->DrawString(listBox1->Items, New Font("Ariel", 12, FontStyle->Regular, GraphicsUnit->Pixel), Brushes->Black, 25, 25);


How do you change it to work in C++ windows forms application?

}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
System::Void printDocument1_PrintPage(System::Object^  sender, 
System::Drawing::Printing::PrintPageEventArgs^  e) 
{
   System::Drawing::Font^ printFont = gcnew System::Drawing::Font("Arial", 12,  
                                         FontStyle::Regular, GraphicsUnit::Pixel);
   e->Graphics->DrawString("Inköpslista",printFont , Brushes::Black, 25, 25);
   e->Graphics->DrawString("___________", printFont, Brushes::Black, 25, 25);
   // Need to loop through all items in ListBox
   e->Graphics->DrawString(listBox1->Items[0]->ToString(), printFont, 
                                           Brushes::Black, 25, 25);
}


I think you should get ab book and learn the syntax and concepts properly.

https://www.amazon.com/Visual-NET-Platform-Experts-Voice/dp/1590596404/ref=sr_1_2?ie=UTF8&qid=1494246800&sr=8-2&keywords=stephen+fraser+c%2B%2B
I tested your code but I cannot print all the items on after the other in a document-page?
What do I do to make this shoppinglist with its items work properly?!
Last edited on
Topic archived. No new replies allowed.