Announcement

Collapse
No announcement yet.

Drucken ohne DruckerDialog

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drucken ohne DruckerDialog

    Hallo,

    ich möchte eine HTML datei direkt in meinem Programm laden und drucken, ich benutze keine Windows.Form. der Code unten funktioniert, aber es öffnet sich der Druckerdialog für drucker auswahl und das möchte ich nicht haben, ich möchte direkt Standarddrucker benutzen, wer weiss wie das geht?

    public void PrintFile(string fullPath)
    {

    Process printProcess = new Process();
    printProcess.StartInfo.FileName = fullPath;
    printProcess.StartInfo.UseShellExecute = true;
    printProcess.StartInfo.Verb = "Print";
    printProcess.StartInfo.CreateNoWindow = true;
    printProcess.EnableRaisingEvents = true;
    printProcess.Start();

    }

  • #2
    das geht sehr einfach mit System.Drawing.Printing.PrintDocument

    das System.Drawing.Printing.PrintPageEventArgs Objekt entspricht dem Graphics Objekt eines Image.

    .. irgendwo :

    Code:
    using System.Drawing.Printing;
    
    
    bool boolPrintDone  = false;
    System.Drawing.Printing.PrintDocument pdoc = new System.Drawing.Printing.PrintDocument();
    
    pdoc.EndPrint += new System.Drawing.Printing.PrintEventHandler(print_done);
    
     pdoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(myPrintPageEventHandler);
    
    public void myPrintEventHandler(object sender,System.Drawing.Printing.PrintPageEventArgs e)
    {
       int z = 100;
       int y = 100;
       System.Drawing.Font fnt18 = new System.Drawing.Font("Arial",18,FontStyle.Bold);
       e.Graphics.DrawString e.Graphics.DrawString("TEST " , fnt18 , rushes.Black, x, z, StringFormat.GenericDefault);
    }
    public static void print_done(object sender,System.Drawing.Printing.PrintEventArgs e)
    {
         boolPrintDone = true;
    }

    Comment

    Working...
    X