环境:c#2008。
我要打印的内容包括两个条形码,三个label,因此我放到一个panel上打印。
        public static void PrintPanel(Panel p)
        {
            PrintPreviewDialog ppvw;
            Graphics mygraphics = p.CreateGraphics();
            Size s = p.Size;
            mBitmap = new Bitmap(s.Width, s.Height, mygraphics);
            Graphics memoryGraphics = Graphics.FromImage(mBitmap);
            IntPtr dc1 = mygraphics.GetHdc();
            IntPtr dc2 = memoryGraphics.GetHdc();
            BitBlt(dc2, 0, 0, p.ClientRectangle.Width, p.ClientRectangle.Height, dc1, 0, 0, 13369376);
            mygraphics.ReleaseHdc(dc1);
            memoryGraphics.ReleaseHdc(dc2);            ppvw = new PrintPreviewDialog();
            ppvw.Width = 105;
            ppvw.Height = 72;
            ppvw.Document = printDoc;
            printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
            //if (ppvw.ShowDialog() != DialogResult.OK)
            //{
            //    printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
            //    return;
            //}
            printDoc.Print();
        }        [System.Runtime.InteropServices.DllImport("gdi32.dll")]
        public static extern long BitBlt(IntPtr HDest, int nXDest, int nYDest, int nWidth, int hHeight, IntPtr HSrc, int nXSrc, int nYSrc, int DwRop);        private static void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(mBitmap, 0, 0);
        }
以上是源程序,呵呵,也是在csdn上找来的,这个可以打印,在激光打印机上勉强可以,能扫出来,单在条码打印机上打印的时候太模糊了,扫描枪根本就识别不出来
请这里的高人帮助。如有别的打印方法更好.谢谢了