注册 登录
编程论坛 C# 论坛

怎么打印内容是空的?

asad 发布于 2022-03-07 22:33, 5506 次点击
private void printDoc_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            printDoc.PrinterSettings.PrinterName = @"\\192.168.135.130\HP LaserJet Professional P1108";   //“打印机名称”;
        }

        private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics MyGraphics = e.Graphics;
            SolidBrush drawBrush = new SolidBrush(Color.Black);
            Font drawFont = new Font("黑体", 10);       //字体 和 大小
            MyGraphics.DrawString("打印内容1", drawFont, drawBrush, 0, 0);
            MyGraphics.DrawString("打印内容2", drawFont, drawBrush,0,100);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.printDoc.PrintPage += new PrintPageEventHandler(this.printDoc_PrintPage);
            printDoc.Print();
        }

[此贴子已经被作者于2022-3-9 10:21编辑过]

5 回复
#2
asad2022-03-07 23:32
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim g As Graphics = e.Graphics
        'g.DrawRectangle(New Pen(New SolidBrush(Color.Red), 2), New Rectangle(10, 0, 100, 60))
        g.DrawString(s, New Font("黑体", 10), New SolidBrush(Color.Black), New Point(10, 62))
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PrintDialog1.Document = PrintDocument1
        If PrintDialog1.ShowDialog = DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End Sub

[此贴子已经被作者于2022-3-10 10:51编辑过]

#3
qq28895779662022-03-10 08:09
以前发的,打印的里面都有,应该比较全了
http://bbs.
全部源码无DLL的坑,收费的只是功能多点、bug少点。代码都差不多

[此贴子已经被作者于2022-3-10 08:12编辑过]

#4
asad2022-03-10 10:47
回复 3楼 qq2889577966
谢谢!!
#5
asad2022-03-23 14:37
回复 3楼 qq2889577966
MyGraphics.DrawString("打印内容2", drawFont, drawBrush,30,100);
请问这30和100是什么单位,是英寸还是厘米?
#6
qq28895779662022-03-28 08:15
像素,dpi96下我是这么转换
pf.Paper_Area = new Size(
                    (int)Math.Floor(宽度 * 3.779527559055118),
                    (int)Math.Floor(高度 * 3.779527559055118)
                    );
1