小编use*_*581的帖子

打印前显示打印对话框

我想在打印文档之前显示打印对话框,因此用户可以在打印前选择其他打印机.打印代码是:

private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(PrintImage);
                pd.Print();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ToString());
            }
        }
        void PrintImage(object o, PrintPageEventArgs e)
        {
            int x = SystemInformation.WorkingArea.X;
            int y = SystemInformation.WorkingArea.Y;
            int width = this.Width;
            int height = this.Height;

            Rectangle bounds = new Rectangle(x, y, width, height);

            Bitmap img = new Bitmap(width, height);

            this.DrawToBitmap(img, bounds);
            Point p = new Point(100, 100);
            e.Graphics.DrawImage(img, p);
        }
Run Code Online (Sandbox Code Playgroud)

这段代码能够打印当前表格吗?

c# printdialog

7
推荐指数
1
解决办法
5万
查看次数

标签 统计

c# ×1

printdialog ×1