ERLEDIGT
NEIN
NEIN
ANTWORTEN
7
7
ZUGRIFFE
1119
1119
EMPFEHLEN
-
Hallo.
Ich habe ein neues Problem. Und zwar möchte ich ein Bild drucken, dass ich in meine Picturebox geladen habe.
Ich habe das mal so probiert:
Funktioniert aber leider nicht, was ich mir aber schon dachte.Code :1 2 3 4 5 6 7 8 9 10
private void image_print(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(); } private void menuItem5_Click(object sender, System.EventArgs e) { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(image_print); pd.Print(); }
Kann mir da vielleicht einer bei helfen, damit ich es richtig mache?
Danke
Jens
-
Viel Spaß damit

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
using System; using System.Windows.Forms; using Microsoft; using System.Drawing; using System.Drawing.Printing; using System.IO; public class PrintingExample : System.Windows.Forms.Form { private System.Windows.Forms.PictureBox pictureBox; private System.Windows.Forms.Button printButton; private Font printFont; public PrintingExample() : base() { // The Windows Forms Designer requires the following call. InitializeComponent(); } // The PrintPage event is raised for each page to be printed. private void pd_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; string line = null; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); Image graph = pictureBox.Image; ev.Graphics.DrawImage(graph, graph.Width, graph.Height); // Print each line of the file. //while(count < linesPerPage && ((line=streamToPrint.ReadLine()) != null)) //{ // yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); // ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); // count++; //} // If more lines exist, print another page. if(line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } // The Windows Forms Designer requires the following procedure. private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(PrintingExample)); this.printButton = new System.Windows.Forms.Button(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.SuspendLayout(); // // printButton // this.printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.printButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.printButton.Location = new System.Drawing.Point(360, 328); this.printButton.Name = "printButton"; this.printButton.Size = new System.Drawing.Size(136, 40); this.printButton.TabIndex = 0; this.printButton.Text = "Print the file."; this.printButton.Click += new System.EventHandler(this.PrintButtonClick); // // pictureBox // this.pictureBox.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox.Image"))); this.pictureBox.Location = new System.Drawing.Point(0, 8); this.pictureBox.Name = "pictureBox"; this.pictureBox.Size = new System.Drawing.Size(496, 312); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // PrintingExample // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(504, 381); this.Controls.Add(this.pictureBox); this.Controls.Add(this.printButton); this.Name = "PrintingExample"; this.Text = "Print Example"; this.Load += new System.EventHandler(this.PrintingExampleLoad); this.ResumeLayout(false); } // This is the main entry point for the application. public static void Main(string[] args) { Application.Run(new PrintingExample()); } void PrintingExampleLoad(object sender, System.EventArgs e) { } void PrintButtonClick(object sender, System.EventArgs e) { try { try { printFont = new Font("Arial", 10); PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage); pd.Print(); } catch (Exception ex1) { MessageBox.Show(ex1.Message); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } }
Neue Windows-Application erstellen, Source über alles drüberkopieren, der PictureBox ein Image zuweisen und drucken. Den Rest kannst dir da selber rausholen
Und mit den Koordinaten wie das Teil ausgedruckt werden soll musst Dich noch ein wenig rumspielen ... aber Drucken an sich geht ohne Troubles.Geändert von Norbert Eder (13.05.04 um 12:58 Uhr)
-
alles.
SuperSache
Danke für die Hilfe
Jens
-
Gern geschehen und schaus dir auch genau an, um draus etwas zu lernen
-
Hallo Norbert,
zunächst danke für deine tollen Beiträge in diesem Forum - da hab ich schon ne Menge raus geholt
Bei diesem Tipp habe ich in meiner Applikation ein Problem, evtl. kannst du mir einen Tipp geben:
Das Bild, dass ich in der pictureBox darstelle ist größer als die Box und wird kleiner skaliert dargestellt. Wenn ich nun mit deinem Code arbeite, kommt
nur eine leere Seite aus dem Drucker - Wenn ich ein Bild lade, dass kleiner/gleichgroß der Box ist, dann kommt das Bild raus.
Hast du eine Idee, woran das liegen kann?
Danke OliWan
...may the force be with you
-
Es gibt ne Methode PrintImageScaled oder so ähnlich .. Guck dir die mal an. So kannst dir Die Ränder des Papier-Formates besorgen und dann entsprechend skalieren.
-
02.08.05 19:32 #7
- Registriert seit
- Jul 2005
- Beiträge
- 17
Hallo, hab hier ein kleines Porblem:
Meine Situation:
Ich zeichne auf die PictureBox mit Hilfe von
Code :1 2
Graphics g; g = pictureBox1.CreateGraphics();
Wenn ich jetzt deinen Code hier benutze, sagt der Compiler mir
"Object reference not set to an instance of an object."
wenn ich mir pictureBox1.Image im debugger angucken sagt der mir das es nicht definiert ist.
Wie kann ich jetzt die Sachen in meiner Picturebox drucken?
Gruß
Jan
-
02.08.05 20:07 #8
- Registriert seit
- Jul 2005
- Beiträge
- 17
hab die Lösung
hab einfach in deinem Code gesagt:
wobei zeichnen() meine Funktion ist die normal über g auf die picturebox zeichnet.Code :1 2 3
g = ev.Graphics; zeichnen(); g = pictureBox1.CreateGraphics();
Klappt alles wunderbar
Danke für die Hilfe :P
mfg
jan
Ähnliche Themen
-
Bild Drucken
Von Kenner3000 im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 27.09.07, 18:12 -
Ein Bild aus einem Panel drucken?
Von Math55 im Forum JavaAntworten: 6Letzter Beitrag: 30.08.07, 12:29 -
Bild aus einer ImagBox drucken
Von meste im Forum .NET Web und KommunikationAntworten: 1Letzter Beitrag: 10.08.06, 15:12 -
Text u. Bild Vorschau und Drucken
Von kurland im Forum Visual Basic 6.0Antworten: 1Letzter Beitrag: 15.06.05, 19:59 -
Bild in mehrere DIN A4's drucken
Von kaZuo im Forum PhotoshopAntworten: 4Letzter Beitrag: 11.09.04, 18:24





Zitieren
Login





