Diskuze: C# - Graphics + Print
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
Zobrazeno 2 zpráv z 2.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
V předchozím kvízu, Test znalostí C# .NET online, jsme si ověřili nabyté zkušenosti z kurzu.
tak jsem to nějak vyřešil:
namespace PrintTest1
{
public partial class Form1 : Form
{
private int page_counter;
//--------------------------------------------------------------------
public Form1()
{
InitializeComponent();
}
//--------------------------------------------------------------------
private void PrintPage(object sender, PrintPageEventArgs ev)
{
ev.HasMorePages = false;
SolidBrush brush = new SolidBrush(Color.Navy);
//int top = page_counter * 200;
PointF p_txt = new PointF(32, 24);
string txt = String.Format("Page {0}", page_counter);
Font font = new Font("Arial", 22.0f, FontStyle.Bold);
ev.Graphics.DrawString(txt, font, brush, p_txt);
page_counter++;
ev.HasMorePages = (page_counter < 10);
}
//--------------------------------------------------------------------
private PrintDocument GetPrintData()
{
PrintDocument pd = new PrintDocument();
pd.DefaultPageSettings.PaperSize = new PaperSize("Page", 800, 1000);
page_counter = 0;
pd.PrintPage += new PrintPageEventHandler(PrintPage);
return pd;
}
//--------------------------------------------------------------------
private void btPrint_Click(object sender, EventArgs e)
{
PrintDialog pd = new PrintDialog();
pd.Document = GetPrintData();
if (pd.ShowDialog() == DialogResult.OK) pd.Document.Print();
}
//--------------------------------------------------------------------
private void btPrintPreview_Click(object sender, EventArgs e)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = GetPrintData();
ppd.ShowDialog();
}
//--------------------------------------------------------------------
}
}
Zobrazeno 2 zpráv z 2.