En iyi yanıtlayıcılar
DataGridView 2.Sayfayı Yazdırma Sorunu

Soru
-
Merhaba,
Formumda bir adet DataGrid var. Yazdırma işlemini yaparken, DataGrid'in satır sayısı kadar yazdırıyor ama DataGrid'de çok fazla veri olduğunda 1 sayfasını yazdırıyor. 2.3.4 vs sayfalara geçmiyor. Nasıl halledebilirim?
Kodlar aşağıda...
private void pdyazici_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Font baslik = new Font("Verdana", 10, FontStyle.Bold); Font baslik2 = new Font("Verdana", 12, FontStyle.Bold); Font govde = new Font("Verdana", 9);
SolidBrush sb = new SolidBrush(Color.Black); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near;
e.Graphics.DrawString(DateTime.Now.ToLongDateString(), baslik, sb, 650, 40);
e.Graphics.DrawString("ALINACAK SİPARİŞ LİSTESİ", baslik2, sb, 270, 80);
e.Graphics.DrawString("Sıra Müş.No Adı Soyadı Adres Telefon 1 Telefon 2", baslik, sb, 30, 140);
e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, 155); for (int i = 0; i < dataGridView1.Rows.Count; i++) { e.Graphics.DrawString((i+1).ToString(), govde, sb, 40, 185 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].Value.ToString(), govde, sb, 90, 185 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), govde, sb, 135, 185 + (i*50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].Value.ToString(), govde, sb, 285, 170 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].Value.ToString(), govde, sb, 285, 185 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].Value.ToString(), govde, sb, 285, 200 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[6].Value.ToString(), govde, sb, 520, 185 + (i * 50)); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[7].Value.ToString(), govde, sb, 660, 185 + (i * 50)); e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, 210 + (i * 50)); } }
private void button33_Click(object sender, EventArgs e) { pdDiyalog.ShowDialog(); }
- Düzenleyen EmrahAyyıldız2 6 Ekim 2017 Cuma 01:53
Yanıtlar
-
int startRowIndex = 0; private void pdyazici_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Font baslik = new Font("Verdana", 10, FontStyle.Bold); Font baslik2 = new Font("Verdana", 12, FontStyle.Bold); Font govde = new Font("Verdana", 9); SolidBrush sb = new SolidBrush(Color.Black); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near; e.Graphics.DrawString(DateTime.Now.ToLongDateString(), baslik, sb, 650, 40); e.Graphics.DrawString("ALINACAK SİPARİŞ LİSTESİ", baslik2, sb, 270, 80); e.Graphics.DrawString("Sıra Müş.No Adı Soyadı Adres Telefon 1 Telefon 2", baslik, sb, 30, 140); e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, 155); int yPos = 0; for (int i = startRowIndex; i < dataGridView1.Rows.Count; i++) { yPos = 185 + (i - startRowIndex) * 50; if (yPos + 25 > e.MarginBounds.Bottom) { startRowIndex = i; e.HasMorePages = true; break; } e.Graphics.DrawString((i+1).ToString(), govde, sb, 40, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].Value.ToString(), govde, sb, 90, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), govde, sb, 135, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].Value.ToString(), govde, sb, 285, yPos - 15); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].Value.ToString(), govde, sb, 285, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].Value.ToString(), govde, sb, 285, yPos + 15); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[6].Value.ToString(), govde, sb, 520, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[7].Value.ToString(), govde, sb, 660, yPos); e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, yPos + 25); } }
Sorunuzun yanıtı bu ise "Yanıt olarak işaretle"yerek siz de forumun işleyişine katkıda bulununuz...
- Düzenleyen MuratAKSARAY 6 Ekim 2017 Cuma 10:44
- Yanıt Olarak İşaretleyen EmrahAyyıldız2 6 Ekim 2017 Cuma 17:54
Tüm Yanıtlar
-
int startRowIndex = 0; private void pdyazici_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Font baslik = new Font("Verdana", 10, FontStyle.Bold); Font baslik2 = new Font("Verdana", 12, FontStyle.Bold); Font govde = new Font("Verdana", 9); SolidBrush sb = new SolidBrush(Color.Black); StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Near; e.Graphics.DrawString(DateTime.Now.ToLongDateString(), baslik, sb, 650, 40); e.Graphics.DrawString("ALINACAK SİPARİŞ LİSTESİ", baslik2, sb, 270, 80); e.Graphics.DrawString("Sıra Müş.No Adı Soyadı Adres Telefon 1 Telefon 2", baslik, sb, 30, 140); e.Graphics.DrawString("----------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, 155); int yPos = 0; for (int i = startRowIndex; i < dataGridView1.Rows.Count; i++) { yPos = 185 + (i - startRowIndex) * 50; if (yPos + 25 > e.MarginBounds.Bottom) { startRowIndex = i; e.HasMorePages = true; break; } e.Graphics.DrawString((i+1).ToString(), govde, sb, 40, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].Value.ToString(), govde, sb, 90, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), govde, sb, 135, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].Value.ToString(), govde, sb, 285, yPos - 15); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].Value.ToString(), govde, sb, 285, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].Value.ToString(), govde, sb, 285, yPos + 15); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[6].Value.ToString(), govde, sb, 520, yPos); e.Graphics.DrawString(dataGridView1.Rows[i].Cells[7].Value.ToString(), govde, sb, 660, yPos); e.Graphics.DrawString("-------------------------------------------------------------------------------------------------------------------------------", baslik, sb, 30, yPos + 25); } }
Sorunuzun yanıtı bu ise "Yanıt olarak işaretle"yerek siz de forumun işleyişine katkıda bulununuz...
- Düzenleyen MuratAKSARAY 6 Ekim 2017 Cuma 10:44
- Yanıt Olarak İşaretleyen EmrahAyyıldız2 6 Ekim 2017 Cuma 17:54
-
hocam oldu yalnız 2. sayfada 2 adet satır var ama sayfanın altından başlıyor
Bir de 19 satır olmasına rağmen 13 satır gösteriyor
- Düzenleyen EmrahAyyıldız2 6 Ekim 2017 Cuma 10:04
-
Kodunuzda hesaplanan üstten mesafeyi düzenledim. Bu haliyle kullanabilirsiniz...
Sorunuzun yanıtı bu ise "Yanıt olarak işaretle"yerek siz de forumun işleyişine katkıda bulununuz...
- Yanıt Olarak İşaretleyen EmrahAyyıldız2 11 Ekim 2017 Çarşamba 18:50
- Yanıt İşaretini Geri Alan EmrahAyyıldız2 11 Ekim 2017 Çarşamba 18:50