Autor Beitrag
TomCat
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Do 01.03.12 11:55 
Hallo,

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

ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Do 01.03.12 12:36 
Hallo TomCat

Also dieser Code funktioniert bei mir einwandfrei (Dialog wird artig angezeigt und ausgeführt):
ausblenden 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 ... :(

_________________
Gruss
mats74
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: 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 Threadstarter
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Do 01.03.12 13:30 
Das ist mein kompletter code:
ausblenden 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, 2525);     
        }


        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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Do 01.03.12 13:40 
Einfach

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


vor dem ShowDialog aufrufen.
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: 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.

_________________
Gruss
mats74
TomCat Threadstarter
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Do 01.03.12 14:23 
Danke!!

jetzt funzt es. :-)