using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace PrintTest
{
/// <summary>
/// 打印雪人图像窗体
/// 2009-02-16 涂聚文
/// summary>
public partial class printDram : Form
{
/// <summary>
/// 打印雪人图像窗体
/// summary>
public printDram()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载
/// summary>
/// <param name="sender">param>
/// <param name="e">param>
private void printDram_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 打印文档
/// summary>
/// <param name="sender">param>
/// <param name="e">param>
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
const int MID = 150;
const int Top = 50;
this.BackColor = Color.Cyan;
this.Width = 310;
this.Height = 260;
this.Text = "simple graphics snowman";
Pen blue = new Pen(Color.Blue);
Pen yellow = new Pen(Color.Yellow);
Pen white = new Pen(Color.White);
Pen red = new Pen(Color.Red);
Pen black = new Pen(Color.Black);
Brush brWhite = white.Brush;
Brush brBlack = black.Brush;
Brush brRed = red.Brush;
Graphics g = e.Graphics;
g.DrawRectangle(blue, 0, 175, 300, 50); //sky
g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
g.FillEllipse(brRed, MID - 35, Top + 35, 70, 50); //top
g.FillEllipse(brRed, MID - 50, Top + 80, 100, 60); //bot
g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
//arms
g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
}
/// <summary>
/// 打印
/// summary>
/// <param name="sender">param>
/// <param name="e">param>
private void btnprint_Click(object sender, EventArgs e)
{
if (MessageBox.Show("是否打印预览?", "打印预览", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
this.printPreviewDialog1.Document = this.printDocument1;
printPreviewDialog1.ShowDialog();
}
else
{
this.printDocument1.Print();//直接打印
}
}
/// <summary>
/// 窗体外观
/// summary>
/// <param name="sender">param>
/// <param name="e">param>
private void printDram_Paint(object sender, PaintEventArgs e)
{
const int MID = 150;
const int Top = 50;
this.BackColor = Color.Cyan;
this.Width = 310;
this.Height = 260;
this.Text = "simple graphics snowman";
Pen blue = new Pen(Color.Blue);
Pen yellow = new Pen(Color.Yellow);
Pen white = new Pen(Color.White);
Pen red = new Pen(Color.Red);
Pen black = new Pen(Color.Black);
Brush brWhite = white.Brush;
Brush brBlack = black.Brush;
Brush brRed = red.Brush;
Graphics g = e.Graphics;
g.DrawRectangle(blue, 0, 175, 300, 50); //sky
g.DrawEllipse(yellow, -40, -40, 80, 80); //sun
g.FillEllipse(brWhite, MID - 20, Top, 40, 40); //head
g.FillEllipse(brWhite, MID - 35, Top + 35, 70, 50); //top
g.FillEllipse(brWhite, MID - 50, Top + 80, 100, 60); //bot
g.FillEllipse(brBlack, MID - 10, Top + 10, 5, 5); //l.eye
g.FillEllipse(brBlack, MID + 5, Top + 10, 5, 5);//r.eye
g.DrawArc(black, MID - 10, Top + 20, 20, 10, -190, -160);//(:
//arms
g.DrawLine(black, MID - 25, Top + 60, Top - 50, MID + 40);
g.DrawLine(black, MID + 25, Top + 60, MID + 55, Top + 60);
g.DrawLine(black, MID - 20, Top + 5, MID + 20, Top + 5);//hat,brim,top
g.FillRectangle(brBlack, MID - 15, Top - 20, 30, 25);
}
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-555239/ ,如需转载,请注明出处,否则将追究法律责任。