Entwickler-Ecke

WinForms - Drucker-Dialog wird nicht angezeigt


TomCat - Do 01.03.12 11:55
Titel: Drucker-Dialog wird nicht angezeigt
Hallo,

ich habe schon alles ausprobiert, aber das Druckerdialog-Fenster wird einfach nicht angezeigt.
Ich verwende Visual Studio 2008 C#.


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
PrintDocument printDocument1 = new PrintDocument(); 
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); 
PrintDialog printDialog1 = new PrintDialog(); 
printDialog1.Document = printDocument1; 
if (printDialog1.ShowDialog() == DialogResult.OK) 
{ 
    printDocument1.Print(); 
}


Hat jemand ne Idee an was das liegen könnte?

THX
TomCat

Moderiert von user profile iconTh69: C#-Tags hinzugefügt
Moderiert von user profile iconTh69: Topic aus C# - Die Sprache verschoben am Do 01.03.2012 um 12:07


mats74 - Do 01.03.12 12:36

Hallo TomCat

Also dieser Code funktioniert bei mir einwandfrei (Dialog wird artig angezeigt und ausgeführt):

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
// Specifies what happens when the PrintPage event is raised.
        private void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            // Draw a picture.
            ev.Graphics.DrawImage(Image.FromFile("C:\\Temp\\Bild1.jpg"), ev.Graphics.VisibleClipBounds);

            // Indicate that this is the last page to print.
            ev.HasMorePages = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PrintDocument printDocument1 = new PrintDocument();
            printDocument1.PrintPage += new PrintPageEventHandler(pd_PrintPage);
            PrintDialog printDialog1 = new PrintDialog();
            printDialog1.Document = printDocument1;
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                printDocument1.Print();
            } 
        }


... also an deinem Code kann es eigentlich nicht liegen.
Ansonsten wüsste ich nicht, an was das liegen soll ... :(


Ralf Jansen - Do 01.03.12 12:56

Kompilier mal dein Projekt explizit als 32Bit Anwendung. Der Printdialog hat Probleme unter 64Bit. Du kannst stattdessen auch mal UseEXDialog am Printdialog setzen. Sieht dann zwar anders aus hat aber keine Probleme mit 64Bit.


TomCat - Do 01.03.12 13:30

Das ist mein kompletter code:

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
                
            Font printFont = new Font("Arial", 18, FontStyle.Bold);
            e.Graphics.DrawString("Dies ist ein Ausdruck", printFont, Brushes.Black, 25, 25);     
        }


        private void button11_Click(object sender, EventArgs e)
        {
           
            PrintDocument printDocument1 = new PrintDocument(); 
            printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); 
            PrintDialog printDialog1 = new PrintDialog(); 
            printDialog1.Document = printDocument1; 
            if (printDialog1.ShowDialog() == DialogResult.OK) 
            { 
            printDocument1.Print(); 
            } 
         }
interessanterweise wenn ich den ShowDialog() nicht aufrufe sondern direkt printDocument1.Print();
wirft der Drucker eine absolut leere Seite aus.


Hab ich evtl. vergesse noch was zu implementieren?

@Ralf Jansen:
wo soll ich das 'UseEXDialog' einfügen ?

Moderiert von user profile iconNarses: C#-Tags hinzugefügt


Ralf Jansen - Do 01.03.12 13:40

Einfach


C#-Quelltext
1:
printDialog1.UseEXDialog = true;                    


vor dem ShowDialog aufrufen.


mats74 - Do 01.03.12 14:19

user profile iconTomCat hat folgendes geschrieben Zum zitierten Posting springen:
Hab ich evtl. vergesse noch was zu implementieren?


Wie schon gesagt, an deinem Code liegt es nicht.
Da muss eine andere Ursache für das aufgetretene Problem sein.
Probiere die von Ralf erwähnten Lösungsansätze aus, vielleicht kommst Du dadurch einen Schritt weiter.


TomCat - Do 01.03.12 14:23

Danke!!

jetzt funzt es. :-)