N
Hat sich erledigt!
Mann muss nur der DrawString-Methode ein weiteres Argument übergeben (stringFormat):
private: void pd_PrintPage( Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ ev ){
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = (float)ev->MarginBounds.Left;
float topMargin = (float)ev->MarginBounds.Top;
String^ line = nullptr;
System::Drawing::Font^ printFont = gcnew System::Drawing::Font("Arial", 9);
StreamReader^ streamToPrint = gcnew StreamReader("ausdruck.txt");
StringFormat^ stringFormat = gcnew StringFormat();
array<float>^ tab = {400, 50, 25, 30}; // Festlegen der Position der TabStopps
stringFormat->SetTabStops(0, tab); // An stringFormat uebergeben
// Anzahl der Zeilen berechnen
linesPerPage = ev->MarginBounds.Height / printFont->GetHeight(ev->Graphics);
try{
// Jede einzelne Zeile des Quelltextes zeichnen/drucken
while (count < linesPerPage && ((line = streamToPrint->ReadLine()) != nullptr))
{
yPos = topMargin + (count * printFont->GetHeight(ev->Graphics));
ev->Graphics->DrawString(line, printFont, Brushes::Black, leftMargin, yPos, stringFormat);
count++;
}
// Falls Seitenende erreicht, Flag setzen, dass Dokument mehrseitig ist
if (!streamToPrint->EndOfStream)
ev->HasMorePages = true;
else
ev->HasMorePages = false;
}
finally{
streamToPrint->Close();
}
}