123456789101112131415161718192021222324252627282930313233343536 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsPrintPreviewControl
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- printPreviewControl1.Document = printDocument1;
- }
- private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
- {
- //获取应用程序的起始路径
- string str = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
- //读取路径下的img.jpg文件
- str += @"\img.jpg";
- //将读取的图片绘制到画布上
- e.Graphics.DrawImage(Image.FromFile(str), 10, 10, 607, 452);
- }
- }
- }
|