Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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...
Posted 8-Dec-12 20:00pm
Comments
chester_it21 at 15-Dec-12 11:12am
   
hi, may be your interest using WPF...i have sample applications for ID Card Print using WPF...You can download here ,in my solution tag..

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 475
1 OriginalGriff 280
2 BillWoodruff 230
3 CPallini 220
4 ChauhanAjay 149
0 OriginalGriff 6,609
1 Sergey Alexandrovich Kryukov 6,240
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100