Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
// Klasse die ein Teile eines Windows Forms ausdruckt #ifndef _FormPrintDOC_H_ #define _FormPrintDOC_H_ using namespace System; using namespace System::ComponentModel; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::Drawing::Printing; using namespace System::IO; class FormPrintDocument : public PrintDocument { private: Font *printFont = null ; System::String *StringToPrint = ""; public: FormPrintDocument(System::String testString) : PrintDocument() { StringToPrint = testString; } virtual ~FormPrintDocument() : ~PrintDocument() { if (printFont != null) delete printFont; } protected: System::void OnBeginPrint(PrintEventArgs ev); System::void OnPrintPage(PrintEventArgs ev); }; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#define _FormPrintDOC_H_ using namespace System; using namespace System::ComponentModel; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::Drawing::Printing; using namespace System::IO; __gc class FormPrintDocument : public PrintDocument { private: Font *printFont; System::String *StringToPrint; public: FormPrintDocument(System::String *testString) //: PrintDocument() { printFont = 0; StringToPrint = ""; StringToPrint = testString; } protected: /*System::*/void OnBeginPrint(PrintEventArgs *ev); /*System::*/void OnPrintPage(PrintEventArgs *ev); }; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include "FormPrintDocument.h" /*System::*/void FormPrintDocument::OnBeginPrint(PrintEventArgs *ev) { PrintDocument::OnBeginPrint(ev); printFont = new Font("Arial", 10); } /*System::*/void FormPrintDocument::OnPrintPage(PrintEventArgs *ev) { PrintDocument::OnPrintPage(ev); ev->Graphics->DrawString(StringToPrint); } |
Zitat
c:\...\FormPrintDocument.cpp(11): error C2664: 'System:rawing:rinting:rintDocument::OnPrintPage' : cannot convert parameter 1 from 'System:rawing:rinting:rintEventArgs __gc *' to 'System:rawing:rinting:rintPageEventArgs __gc *'
Quellcode |
|
1 |
PrintDocument::OnBeginPrint(ev); |
Zitat
To create a print job
Add a PrintDocument component to your form.
Right-click your form and choose View Code.
Write code to handle the PrintPage event.
You will have to code your own printing logic. Additionally, you will have to specify the material to be printed.
In the example below, a sample graphic (a red rectangle) is created in the PrintPage event handler to act as material to be printed.
C-/C++-Quelltext
1 2 3 4 5 6 7 private: void printDocument1_PrintPage(System::Object ^ sender, System::Drawing::Printing::PrintPageEventArgs ^ e) { e->Graphics->FillRectangle(Brushes::Red, Rectangle(500, 500, 500, 500)); }
Werbeanzeige