ERLEDIGT
JA
JA
ANTWORTEN
11
11
ZUGRIFFE
1847
1847
EMPFEHLEN
-
27.01.06 12:39 #1
- Registriert seit
- Oct 2004
- Beiträge
- 483
Hi Mädels,
habe nochmal ein klitzekleines Problem. Ich habe mir so einen PrintingDialog erstellt, und dort jetzt meinen Report erstellt. Problem nur, wie kann ich dem sagen das ich jetzt auf eine Neue Seite schreiben will ?
Also wie komme ich von Blatt 1 auf Blatt 2 ?
Dieses "HasMorePages = true" produziert bei mir entweder endlos viele neue Blätter, oder garkeins
Oder muss man dann einfach über die Blattlänge hinaus schreiben ?
Gruß
MFC OpenGLSprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
28.01.06 16:18 #2
- Registriert seit
- Oct 2004
- Beiträge
- 483
Keiner ne Idee ? Cosmo, Norbert, Zipo... ?
Sprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
Hier ein Link für dich:
http://de.gotdotnet.com/quickstart/w...sPrinting.aspx
-
28.01.06 18:48 #4
- Registriert seit
- Oct 2004
- Beiträge
- 483
Dann muss ich irgend einen Fehler in meinem Code haben, denn so habe ich das gemacht

Werde jetzt mal mein Noti auf VS2005 umstellen, und dann nochmal schaun.
Danke Norbert.
Gruß
MFC OpenGLSprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
29.01.06 14:40 #5
- Registriert seit
- Oct 2004
- Beiträge
- 483
So habe ich jetzt meinen Testcode... Der erzeugt einfach ein testtext mit der Zeilennummer, und soll beim 60. auf Seite 2 weiterschreiben. Problem, sofern er auf Seite 1 bleibt, geht alles reibungslos. Er schreibt seine X Zeilen und bricht dann ab... Seite okey... alles Super.PHP-Code:float lpp = 0;
float yPos = 0;
int count = 0;
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
String line = null;
string[] testtext = new string[101];
for (int i = 0; i < 100; i++)
testtext[i] = i.ToString();
testtext[70] = null;
//Work out the number of lines per page
//Use the MarginBounds on the event to do this
lpp = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
//Now iterate over the file printing out each line
//NOTE WELL: This assumes that a single line is not wider than the page width
//Check count first so that we don't read line that we won't print
while (count < lpp && ((line = testtext[count]) != null))
{
yPos = topMargin + (count * printFont.GetHeight(e.Graphics));
//Print Preview control will not work.
e.Graphics.DrawString(testtext[count], printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());
count++;
}
//If we have more lines then print another page
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
Aber wehe es soll eine 2. Seite geschrieben werden, wie jetzt oben im Code. Dann schreibt er unendlich viele neue Seiten, und kommt auf kein Ende
Ich verstehe einfach nicht wieso. Auch verstehe ich nicht, wieso der nach dem HasMorePages die Funktion schreinbar selbstständig nochmal aufruft (stört mich zwar nicht, aber wissen wieso würde ichs trotzdem gerne)
Kann einer von euch mal den Code bei sich reinpacken, und schaun das der dann an der 2. oder x. Seite auch anhält ? Das wäre echt klasse, weil ich echt kurz vor dem Verzweifeln bin.
Aso Norbert, das ist überigens der Code aus deinem Link. Nur soweit abgeändert das ich nicht aus einer Textdatei lese, sondern aus einem String.
Danke schonmal.
Gruss
MFC OpenGLSprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
Schon mal mit dem Debugger durchgegangen und angesehen warum er immer wieder weiterdruckt?
-
29.01.06 16:19 #7
- Registriert seit
- Oct 2004
- Beiträge
- 483
Hi Norbert,
Ups
Habe die Count Varialbe in der Funktion gemacht... daran lags das er dann ne Endlosschleife hatte.
Aber mein Problem lößt er damit auch nicht.
Es wird zwar eine 2. Seite erzeugt, und dann beendet sich die Funktion auch, aber es wird nichts auf die 2. Seite geschrieben
Das Problem liegt an der While, da er durch das count < lpp keine 2. Seite beschreiben darf.
Kann ich den
"e.Graphics.DrawString(testtext[count], printFont, Brushes.Black, leftMargin,
yPos, new StringFormat());"
Befehl nicht irgendwie anweisen, das er auf die 2. Seite schreiben soll ? Das muss doch machbar sein.
Also das mit dem erzeugen der 2. Seite geht ja nun, aber das reinschreiben nicht.
An den Zählern kanns auch nicht liegen, habe die nun ausserhalb der Funktion deklariert. Bin total ratlos.
Gruss
MFC OpenGL
Sprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
Wieso sollte er die zweite Seite nicht beschreiben dürfen? Dein Code wird doch für jede Seite erneut ausgeführt. Ergo wird auch deine Variable lpp wieder zurückgesetzt.
Vermutlich liegts auch daran, dass du dein testtext innerhalb von PrintPage definierst .. wird ja dann bei jeder neuen Seite wieder neu initialisiert etc.
-
30.01.06 00:14 #9
- Registriert seit
- Oct 2004
- Beiträge
- 483
Nein Norbert, die Variablen sind außerhalb definiert, und da der testtext immer gleich ist, ist es egal wo der definiert wird.
Zitat von Norbert Eder
Hast du den Code bei dir mal getestet ?Sprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
Hallo Darki!
Hab jetzt nicht so die Zeit um das mal schnell zu testen.
Ich würd aber sagen, dass wenn Du die ZeileinCode :1
lpp = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
änderst, solltest Du bis zur letzten Zeile drucken können.Code :1
lpp [highlight]+=[/highlight] e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
Wie Norbert schon sagte, lpp wir bei jedem Seitendruck zurück gesetzt.
Und count repräsentiert ja die gedruckten Zeilen...
lg, cosmoMfG,
Christian
Wer sein Problem definiert, hat es schon halb gelöst!
Bitte markiert eure Themen als erledigt. Sonst macht so ein Forum als Nachschlagewerk keinen Sinn.
The Code Project! - C# Programming | C# / VB.NET Pendants
Regeln + Netiquette
Liebe FIAEs, verlasst euch nicht auf das was in der Berufsschule "vermittelt" wird
und vor allem nicht auf das, was euch die IHK dazu erzählt!
Die haben so viel Ahnung von dem Gewerk, wie der Bundestag vom Haushalt...
-
30.01.06 09:59 #11
- Registriert seit
- Oct 2004
- Beiträge
- 483
Code :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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
[SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][SIZE=2] lpp = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][SIZE=2] yPos = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] count = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][SIZE=2] leftMargin = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][SIZE=2] topMargin = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] line = [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][] testtext = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2][1001]; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]Font[/COLOR][/SIZE][SIZE=2] printFont; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] sitenumber = 1; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] linecount = 0; [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] printDocument1_PrintPage([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, System.Drawing.Printing.[/SIZE][SIZE=2][COLOR=#008080]PrintPageEventArgs[/COLOR][/SIZE][SIZE=2] e) { [/SIZE][SIZE=2][COLOR=#008000]//Work out the number of lines per page [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]//Use the MarginBounds on the event to do this [/COLOR][/SIZE][SIZE=2]lpp = e.MarginBounds.Height / printFont.GetHeight(e.Graphics); [/SIZE][SIZE=2][COLOR=#008000]//Now iterate over the file printing out each line [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]//NOTE WELL: This assumes that a single line is not wider than the page width [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]//Check count first so that we don't read line that we won't print [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2] (count < (lpp*sitenumber) && ((line = testtext[count]) != [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2])) { yPos = topMargin + (linecount * printFont.GetHeight(e.Graphics)); [/SIZE][SIZE=2][COLOR=#008000]//Print Preview control will not work. [/COLOR][/SIZE][SIZE=2]e.Graphics.DrawString(testtext[count], printFont, [/SIZE][SIZE=2][COLOR=#008080]Brushes[/COLOR][/SIZE][SIZE=2].Black, leftMargin, yPos, [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]StringFormat[/COLOR][/SIZE][SIZE=2]()); linecount++; count++; } [/SIZE][SIZE=2][COLOR=#008000]//If we have more lines then print another page [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (line != [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2]) { linecount = 0; sitenumber++; e.HasMorePages = [/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2]; } [/SIZE][SIZE=2][COLOR=#0000ff]else [/COLOR][/SIZE][SIZE=2]e.HasMorePages = [/SIZE][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][SIZE=2]; } [/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#008080]EventArgs[/COLOR][/SIZE][SIZE=2] e) { printFont = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]Font[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#800000]"Arial"[/COLOR][/SIZE][SIZE=2], 10); lpp = 0; yPos = 0; count = 0; linecount = 0; leftMargin = 20; topMargin = 40; line = [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2]; [/SIZE][SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i = 0; i < 1000; i++) testtext[i] = i.ToString(); testtext[700] = [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2]; printPREdoc.Document = printdoc; printPREdoc.SetBounds(0, 0, 1024, 768); printPREdoc.ShowDialog(); } [/SIZE]
Für alle die auch mal so ein Abge****tes Problem haben wie ich
Oben ist der Code, der funktioniert... Ist nur nen Testcode, Bezeichner oder sowas mach ich an Wochenenden (und Montag morgens ist noch Wochenende
) nicht.
Nörgler wenden sich bitte an meine Mail Addi -> Nörgler@Papierkorb.de
Wünsch euch nen schönen Tach und dir Norbert, nochmal danke für deine Hilfe !
Gruss
MFC OpenGLSprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
-
30.01.06 10:02 #12
- Registriert seit
- Oct 2004
- Beiträge
- 483
OK Cosmo, deine Lösung ist natürlich wieder meiner um Längen überlegen

So gehts auch *g*Sprache : C/C++/C# & MFC
Compiler : MSVC++ 7 / VS2003.net
OS : Windows XP/2k
Ähnliche Themen
-
Print Dialog
Von Alaitoc im Forum .NET Windows FormsAntworten: 6Letzter Beitrag: 05.12.07, 16:19 -
Mehrfach Print-Befehl ausgeben ohne Print-Dialog?
Von preko im Forum Javascript & AjaxAntworten: 1Letzter Beitrag: 23.11.07, 10:07 -
VBA Excel: Belegte Zellen in neues Blatt kopieren
Von Purple-Haze im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 12.03.05, 09:44 -
Bei print() neues Template nutzen
Von Vaio82 im Forum Javascript & AjaxAntworten: 0Letzter Beitrag: 17.05.04, 09:48 -
Samba Printing Problems
Von format_c im Forum Linux & UnixAntworten: 2Letzter Beitrag: 14.11.02, 20:03





Zitieren
Login





