none
C#Yazdırma Komutu

    Soru

  • Formdaki textbox ve comboboxların içeriklerinin print edilmesini nasıl yapabiliriz.Textbox ve combobox ların çıktısını nasıl alırız.

                

    private void button8_Click(object sender, EventArgs e)
            {
                PrintDocument PD = new PrintDocument();
                PD.PrintPage += new PrintPageEventHandler(OnPrintDocument);

                try
                {
                    PD.Print();
                }
                catch
                {
                    Console.WriteLine("Yazıcı çıktısı alınamıyor...");
                }
                finally
                {
                    PD.Dispose();
                } 
            }
            private static void OnPrintDocument(object sender, PrintPageEventArgs e)
            {

                e.Graphics.DrawRectangle(Pens.Red, 20, 20, 100, 100);
            } 
        }

    Bu şekilde yazdırma sayfası gözüküyor(İçi boş) Bu programda nasıl bir değişiklik yaparsak textbox ve comboboxdaki değerlerin çıktısı alınır.

    21 Haziran 2012 Perşembe 09:25

Yanıtlar

  • public int i=0;

     private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
                int x=135,y=135,say=100;
                System.Drawing.Printing.PageSettings p = printDocument1.DefaultPageSettings;
                //e.Graphics.DrawLine(new Pen(Color.Black,2),p.Margins.Left,125,p.PaperSize.Width-p.Margins.Right,125);
                e.Graphics.DrawString("Tc Kimlik No",this.label1.Font,Brushes.Black,100,130);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 150, p.PaperSize.Width - p.Margins.Right, 150);
                e.Graphics.DrawString("Adı", this.label2.Font, Brushes.Black,100,160);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 175, p.PaperSize.Width - p.Margins.Right, 175);
                e.Graphics.DrawString("Soyadı", this.label3.Font, Brushes.Black,100,185);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 200, p.PaperSize.Width - p.Margins.Right, 200);
                e.Graphics.DrawString("Cep Telefonu", this.label4.Font, Brushes.Black, 100, 210);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 225, p.PaperSize.Width - p.Margins.Right, 225);
                e.Graphics.DrawString("Pozisyon", this.label5.Font, Brushes.Black, 100, 235);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 250, p.PaperSize.Width - p.Margins.Right, 250);
                e.Graphics.DrawString("Plaka No", this.label6.Font, Brushes.Black, 100, 260);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 275, p.PaperSize.Width - p.Margins.Right, 275);
                e.Graphics.DrawString("Marka", this.label6.Font, Brushes.Black, 100, 285);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 300, p.PaperSize.Width - p.Margins.Right, 300);
                e.Graphics.DrawString("Marka", this.label6.Font, Brushes.Black, 100, 310);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 300, p.PaperSize.Width - p.Margins.Right, 325);


                while (i==0) {
                    //x += 25;

                string TcKimlikNo=textBox1.Text;
                string Adi = textBox2.Text;
                string Soyadi = textBox3.Text;
                string Ceptel = textBox4.Text;
                string Pozisyon = comboBox2.Text;
                string PlakaNo = textBox5.Text;
                string Marka = textBox6.Text;

                e.Graphics.DrawString(TcKimlikNo, this.label1.Font, Brushes.Black, 250,130);
                e.Graphics.DrawString(Adi, this.label2.Font, Brushes.Black, 250, 160);
                e.Graphics.DrawString(Soyadi, this.label3.Font, Brushes.Black, 250, 185);
                e.Graphics.DrawString(Ceptel, this.label4.Font, Brushes.Black, 250, 210);
                e.Graphics.DrawString(Pozisyon, this.label5.Font, Brushes.Black, 250, 235);
                e.Graphics.DrawString(PlakaNo, this.label6.Font, Brushes.Black, 250, 260);
                e.Graphics.DrawString(Marka, this.label7.Font, Brushes.Black, 250, 285);
                //e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, x+20, p.PaperSize.Width - p.Margins.Right, x+20);
                i++;
                if ((x + y + 20) > (p.PaperSize.Height + 80 - p.Margins.Bottom + 80))
                {
                    e.HasMorePages = true;
                    break;
                }
                }
                if (i >= say) {
                    e.HasMorePages = false;
                    i = 0;
                }
            }

       private void yazdir_Click(object sender, EventArgs e)
            {
                printDocument1.Print();
            }

    bu şekilde oluyor.

                
    21 Haziran 2012 Perşembe 21:18

Tüm Yanıtlar

  • private static void OnPrintDocument(object sender, PrintPageEventArgs e)
            {
                Font f = new Font(FontFamilies.SansSerif, 20F);
                e.Graphics.DrawRectangle(Pens.Red, 20, 20, 100, 100);
                e.Graphics.DrawString(TextBox1.Text, f, Brushes.Black, new PointF(30,30)); 
                e.Graphics.DrawString(TextBox2.Text, f, Brushes.Black, new PointF(30,50));
            } 
    buna benzer bir ilave ile kırmızı dörtgenin içine yazması gerekir

    e-mail: onay[nokta]yalciner[at]hotmail[nokta]com
    MCC

    21 Haziran 2012 Perşembe 19:11
  • public int i=0;

     private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
                int x=135,y=135,say=100;
                System.Drawing.Printing.PageSettings p = printDocument1.DefaultPageSettings;
                //e.Graphics.DrawLine(new Pen(Color.Black,2),p.Margins.Left,125,p.PaperSize.Width-p.Margins.Right,125);
                e.Graphics.DrawString("Tc Kimlik No",this.label1.Font,Brushes.Black,100,130);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 150, p.PaperSize.Width - p.Margins.Right, 150);
                e.Graphics.DrawString("Adı", this.label2.Font, Brushes.Black,100,160);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 175, p.PaperSize.Width - p.Margins.Right, 175);
                e.Graphics.DrawString("Soyadı", this.label3.Font, Brushes.Black,100,185);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 200, p.PaperSize.Width - p.Margins.Right, 200);
                e.Graphics.DrawString("Cep Telefonu", this.label4.Font, Brushes.Black, 100, 210);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 225, p.PaperSize.Width - p.Margins.Right, 225);
                e.Graphics.DrawString("Pozisyon", this.label5.Font, Brushes.Black, 100, 235);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 250, p.PaperSize.Width - p.Margins.Right, 250);
                e.Graphics.DrawString("Plaka No", this.label6.Font, Brushes.Black, 100, 260);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 275, p.PaperSize.Width - p.Margins.Right, 275);
                e.Graphics.DrawString("Marka", this.label6.Font, Brushes.Black, 100, 285);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 300, p.PaperSize.Width - p.Margins.Right, 300);
                e.Graphics.DrawString("Marka", this.label6.Font, Brushes.Black, 100, 310);
                e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, 300, p.PaperSize.Width - p.Margins.Right, 325);


                while (i==0) {
                    //x += 25;

                string TcKimlikNo=textBox1.Text;
                string Adi = textBox2.Text;
                string Soyadi = textBox3.Text;
                string Ceptel = textBox4.Text;
                string Pozisyon = comboBox2.Text;
                string PlakaNo = textBox5.Text;
                string Marka = textBox6.Text;

                e.Graphics.DrawString(TcKimlikNo, this.label1.Font, Brushes.Black, 250,130);
                e.Graphics.DrawString(Adi, this.label2.Font, Brushes.Black, 250, 160);
                e.Graphics.DrawString(Soyadi, this.label3.Font, Brushes.Black, 250, 185);
                e.Graphics.DrawString(Ceptel, this.label4.Font, Brushes.Black, 250, 210);
                e.Graphics.DrawString(Pozisyon, this.label5.Font, Brushes.Black, 250, 235);
                e.Graphics.DrawString(PlakaNo, this.label6.Font, Brushes.Black, 250, 260);
                e.Graphics.DrawString(Marka, this.label7.Font, Brushes.Black, 250, 285);
                //e.Graphics.DrawLine(new Pen(Color.Black, 2), p.Margins.Left, x+20, p.PaperSize.Width - p.Margins.Right, x+20);
                i++;
                if ((x + y + 20) > (p.PaperSize.Height + 80 - p.Margins.Bottom + 80))
                {
                    e.HasMorePages = true;
                    break;
                }
                }
                if (i >= say) {
                    e.HasMorePages = false;
                    i = 0;
                }
            }

       private void yazdir_Click(object sender, EventArgs e)
            {
                printDocument1.Print();
            }

    bu şekilde oluyor.

                
    21 Haziran 2012 Perşembe 21:18