打印自定义尺寸 [英] Printing Custom size

查看:118
本文介绍了打印自定义尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人;

我正在尝试使用卡片打印机在特殊尺寸的卡片上打印。

我写的代码在我的笔记本电脑上工作得很好,然后当我使用不同的屏幕时我分析它还取决于屏幕尺寸。



所以请帮助我在我的代码中应该根据屏幕分辨率调整大小。



Dear All;
I am trying to print on Card with special size using a card printer.
I wrote the code which was working great on my laptop , then when I used defferent screen I analys that it also depends on the screen size.

So Kindly Help me what modificication should be done in my code to adjust size depending on the screen resolution.

Panel pannel = null;

Bitmap MemoryImage;

public void GetPrintArea(Panel pnl)
{

    Graphics g = this.CreateGraphics();
    MemoryImage = new Bitmap(Convert.ToInt32(3.375 * g.DpiX), Convert.ToInt32(2.125 * g.DpiY));
    //Rectangle rect = new Rectangle(0, 0, Convert.ToInt32(3.375 * g.DpiX), Convert.ToInt32(2.125 * g.DpiY));
    pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, Convert.ToInt32(3.375 * g.DpiX), Convert.ToInt32(2.125 * g.DpiY)));
    MemoryImage.Save("pic.jpg");
}
public void Print(Panel pnl)
{
    pannel = pnl;

    GetPrintArea(pnl);
    Graphics g = this.CreateGraphics();
    printdoc1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom Size", Convert.ToInt32(3.375 * g.DpiX), Convert.ToInt32(2.125 * g.DpiY));


    PageSetupDialog setupDlg = new PageSetupDialog();
    setupDlg.Document = printdoc1;
    setupDlg.AllowOrientation = true;
    setupDlg.AllowPaper = true;
    setupDlg.AllowPrinter = true;
    if (setupDlg.ShowDialog() == DialogResult.OK)
    {
        printdoc1.DefaultPageSettings =
        setupDlg.PageSettings;
        printdoc1.PrinterSettings =
        setupDlg.PrinterSettings;
    }
    previewdlg.Document = printdoc1;
    //previewdlg.ShowDialog();
    DialogResult result = previewdlg.ShowDialog();
    if (result == DialogResult.OK)
    {
        printdoc1.Print();
    }
}

private void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{

    Graphics g = this.CreateGraphics();
    Rectangle pagearea = new Rectangle(0, 0, Convert.ToInt32(3.375 * g.DpiX), Convert.ToInt32(2.125 * g.DpiY));
    //pagearea.Width = 245;
    // e.Graphics.PageUnit = GraphicsUnit.Millimeter;
    e.Graphics.DrawImage(MemoryImage, pagearea);

}
private void printcardbtn_Click(object sender, EventArgs e)
{
     Print(pnlcard);

}





任何建议都将受到赞赏。

问候......



any suggestion would be appreciated .
regards...

推荐答案

http://www.codeproject.com/Articles/509383/Sample-Report-ID-Card-Using-WPF [ ^ ]


这篇关于打印自定义尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆