private void CetakTulisan(object sender, PrintPageEventArgs e) { int JumBarisPerHalaman = (int)((e.MarginBounds.Height - MarginBawah) / JenisFont.GetHeight(e.Graphics)); float y = MarginAtas; int jumBaris = 0; string tulisanCetak = FileCetak.ReadLine(); while (jumBaris < JumBarisPerHalaman && tulisanCetak != null) { y = MarginAtas + (jumBaris * jenisFont.GetHeight(e.Graphics)); e.Graphics.DrawString(tulisanCetak, JenisFont, Brushes.Black, MarginKiri, y); jumBaris++; tulisanCetak = FileCetak.ReadLine(); } if (tulisanCetak != null) { e.HasMorePages = true; } else { e.HasMorePages = false; } }
public string CetakKePrinter(string pTipe) { try { PrintDocument p = new PrintDocument(); if (pTipe == "tulisan") { p.PrintPage += new PrintPageEventHandler(CetakTulisan); } p.Print(); FileCetak.Close(); return("1"); } catch (Exception e) { return("Proses Cetak gagal. Pesan Kesalahan = " + e.Message); } }
public string CetakKePrinter(string pTipe) { try { //buat objek untuk mencetak PrintDocument p = new PrintDocument(); if (pTipe == "tulisan") //jika tipe yang akan dicetak adalah teks atau tulisan { //tambahkan event handler untuk mencetak tulisan p.PrintPage += new PrintPageEventHandler(CetakTulisan); } //cetak tulisan p.Print(); FileCetak.Close(); return("1"); } catch (Exception ex) { return("Proses cetak gagal. Pesan kesalahan = " + ex.Message); } }
private void CetakTulisan(object sender, PrintPageEventArgs e) { //hitung jumlah baris maksimal yang dapat ditampilkan pada 1 halaman kertas int jumBarisPerHalaman = (int)((e.MarginBounds.Height - MarginBawah) / JenisFont.GetHeight(e.Graphics)); //untuk menyimpan posisi y terakhir tulisan yang telah tercetak float y = marginAtas; //untuk mnyimpan jumlah bariss tulisan yang telah tercetak int jumBaris = 0; //untuk menyimpan tulisan yang akan dicetak string tulisanCetak = FileCetak.ReadLine(); //baca filestream untuk mencetak tiap baris tulisan while (jumBaris < jumBarisPerHalaman && tulisanCetak != null) { y = MarginAtas + (jumBaris * JenisFont.GetHeight(e.Graphics)); //cetak tulisan sesuai jenis font dan margin (warna tulisan hitam) e.Graphics.DrawString(tulisanCetak, JenisFont, Brushes.Black, MarginKiri, y); //jumlah baris tercetak ditambah 1 jumBaris++; //baca baris file berikutnya tulisanCetak = FileCetak.ReadLine(); } //jika masih belum selesai mencetak, cetak di halaman berikutnya if (tulisanCetak != null) { e.HasMorePages = true; } else { e.HasMorePages = false; } }