Forum

C# Etiket Basımı
 
Bildirimler
Hepsini Temizle

C# Etiket Basımı

2 Yazılar
2 Üyeler
0 Likes
1,840 Görüntüleme
(@Anonim)
Gönderiler: 0
Konu başlatıcı
 

Bir Projede text içine yazılan bir metni tek satırlık bir etiket haline
getirmek istiyorum,  ben textbox içine metni yazıcam ve butona
bastığımda yazıcıdan çıktı almak istiyorum, bunu nasıl yapabilirim.

crystal raporla denedim fakat tek satırlık bir metin için biraz fazla kompleks yöntem oldu.

 
Gönderildi : 10/10/2011 18:53

(@ferhatkaratas)
Gönderiler: 100
Estimable Member
 

Projenizin windows application olduğunu düşünüyorum. Bu kodla ekrandaki  tüm kontrollerin text'ini yazdırırsınız. Yazdırmak istemediğiniz control'u foreach içinde tespit edip iptal edebilirsiniz.

 

        void thePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            int linesPerPage = 0;
            int charsOnPage = 0;

            e.Graphics.MeasureString(this.strToPrint, this.Font, e.MarginBounds.Size, StringFormat.GenericTypographic, out charsOnPage, out linesPerPage);
            e.Graphics.DrawString(this.strToPrint, this.Font, Brushes.Black, e.MarginBounds, StringFormat.GenericTypographic);
            this.strToPrint = this.strToPrint.Substring(charsOnPage);
            e.HasMorePages = (this.strToPrint.Length > 0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument f = new System.Drawing.Printing.PrintDocument();
            PrintDialog theDialog = new PrintDialog();
            System.Drawing.Printing.PrintDocument thePrintDocument = new System.Drawing.Printing.PrintDocument();
            theDialog.Document = thePrintDocument;
            theDialog.ShowDialog();
            foreach (Control curControl in this.Controls)
            {
                this.strToPrint += curControl.Text + " ";
            }
            //the for each loop above is probably useless for you, just take it out and only append to "strToPrint" the text you want to print from wherever it is.

            thePrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(thePrintDocument_PrintPage);
            thePrintDocument.Print();
        }

 

 

Ferhat Karataş
fkaratas.com

 
Gönderildi : 12/10/2011 16:04

Paylaş: