⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Barcode label printing on Zebra printers Using Print DLL s. To use this code, we have to download su
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    cntrl.Left = (int)(((cntrl.Left) * (PSWAW) * (maxLength * dpiX)) / (frm.resWidthReference * (frm.Width)));

                    if (cntrl is System.Windows.Forms.TabControl)
                    {
                        foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls)
                        {
                            foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls)
                            {
                                cntrl2.Width = (int)(((cntrl2.Width) * (PSWAW) * (maxLength * dpiX)) / (frm.resWidthReference * (frm.Width)));
                                cntrl2.Left = (int)(((cntrl2.Left) * (PSWAW) * (maxLength * dpiX)) / (frm.resWidthReference * (frm.Width)));
                            }
                        }
                    }
                }

                frm.Width = (int)((frm.Width) * (maxLength * dpiX)) / (frm.Width);

            }

            frm.resWidthReference = frm.Width; // Set the reference width to the new value.


            // A similar calculation is performed below for the height & top values for each control ...

            if (!((Screen.PrimaryScreen.Bounds.Width <= (1.5) * (Screen.PrimaryScreen.Bounds.Height))
            && (Screen.PrimaryScreen.Bounds.Height <= (1.5) * (Screen.PrimaryScreen.Bounds.Width))))
            {
                if ((Screen.PrimaryScreen.Bounds.Height) > (Screen.PrimaryScreen.Bounds.Width))
                {
                    PSWAH = (int)((1.33) * PSWAW);
                }

            }

            float dpiY = graphics.DpiY;

            if (frm.bInitialScale == true)
            {
                if (Symbol.Win32.PlatformType == "PocketPC")
                {
                    frm.Height = PSWAH;
                }
                else
                {
                    frm.Height = (int)((frm.Height) * (PSWAH)) / (frm.resHeightReference);

                }
            }

            if ((frm.Height <= maxLength * dpiY) || frm.bSkipMaxLen == true)
            {
                foreach (System.Windows.Forms.Control cntrl in frm.Controls)
                {

                    cntrl.Height = ((cntrl.Height) * (frm.Height)) / (frm.resHeightReference);
                    cntrl.Top = ((cntrl.Top) * (frm.Height)) / (frm.resHeightReference);


                    if (cntrl is System.Windows.Forms.TabControl)
                    {
                        foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls)
                        {
                            foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls)
                            {
                                cntrl2.Height = ((cntrl2.Height) * (frm.Height)) / (frm.resHeightReference);
                                cntrl2.Top = ((cntrl2.Top) * (frm.Height)) / (frm.resHeightReference);
                            }
                        }
                    }

                }

            }
            else
            {
                foreach (System.Windows.Forms.Control cntrl in frm.Controls)
                {

                    cntrl.Height = (int)(((cntrl.Height) * (PSWAH) * (maxLength * dpiY)) / (frm.resHeightReference * (frm.Height)));
                    cntrl.Top = (int)(((cntrl.Top) * (PSWAH) * (maxLength * dpiY)) / (frm.resHeightReference * (frm.Height)));


                    if (cntrl is System.Windows.Forms.TabControl)
                    {
                        foreach (System.Windows.Forms.TabPage tabPg in cntrl.Controls)
                        {
                            foreach (System.Windows.Forms.Control cntrl2 in tabPg.Controls)
                            {
                                cntrl2.Height = (int)(((cntrl2.Height) * (PSWAH) * (maxLength * dpiY)) / (frm.resHeightReference * (frm.Height)));
                                cntrl2.Top = (int)(((cntrl2.Top) * (PSWAH) * (maxLength * dpiY)) / (frm.resHeightReference * (frm.Height)));
                            }
                        }
                    }

                }

                frm.Height = (int)((frm.Height) * (maxLength * dpiY)) / (frm.Height);

            }

            frm.resHeightReference = frm.Height;

            if (frm.bInitialScale == true)
            {
                frm.bInitialScale = false; // If this was the initial scaling (from scratch), it's now complete.
            }
            if (frm.bSkipMaxLen == true)
            {
                frm.bSkipMaxLen = false; // No need to consider the maximum length restriction now.
            }


        }

        /// <summary>
		/// The main entry point for the application.
		/// </summary>

		static void Main() 
		{
            Form1 frm1 = new Form1();
            frm1.DoScale();
            Application.Run(frm1);
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
            try
            {
			foreach (string printerName in PrinterSettings.InstalledPrinters)
				this.comboBox1.Items.Add(printerName);
            }
            catch (Exception)
            {
                System.Windows.Forms.MessageBox.Show("Printer driver not found", "CS_PrinterSample1");
                this.Close();
                return;
            }

			comboBox1.SelectedIndex = 0;

			// Add MainMenu if Pocket PC
			if(Symbol.Win32.PlatformType == "PocketPC")
			{
				this.Menu = new MainMenu();
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
            /*PrintDocument */ prnDoc = new PrintDocument();
			prnDoc.PrinterSettings.PrinterName = (string)comboBox1.SelectedItem;
			if (!prnDoc.PrinterSettings.IsValid)
			{
				MessageBox.Show("Invalid printer!");
				return;
			}

			prnDoc.PrintPage += new PrintPageEventHandler(OnPrintPage);

			try
			{
				prnDoc.Print();
			}
			catch (Exception err)
			{
				MessageBox.Show(err.Message);
			}
		}

		private void OnPrintPage(object obj, PrintPageEventArgs ppea)
		{

            // Print a barcode
            int x= 10, y = 20;
            RectangleF barcodeRect = new RectangleF(10, y, 100, 30);
            ppea.SymbolGraphics.DrawBarCode(BarCodeTypes.PDF417, "20 Dec 2008, 5 p.m BAR-LOC02, 150000.00", barcodeRect,
                                            null, RectangleF.Empty);

            y += 50;
			// Print a string
            // Old code
            SolidBrush brush = new SolidBrush(Color.Black);
            RectangleF textRect = new RectangleF(10, y, 100, 20);
           
            Font font = new Font("Tahoma", 11.0F, FontStyle.Regular);
            ppea.SymbolGraphics.DrawString("Depositor: Senthil", font, brush, textRect); 
            Image image = new Bitmap("\\Program Files\\SignaturePPC\\CapturedSignature1.bmp");
            ppea.SymbolGraphics.DrawImage(image, 10, y);
            y = image.Height + 20;

            textRect = new RectangleF(10, y, 100, 20);
            image.Dispose();
            ppea.SymbolGraphics.DrawString("Custodian: James", font, brush, textRect);
            image = new Bitmap("\\Program Files\\SignaturePPC\\CapturedSignature2.bmp");
            ppea.SymbolGraphics.DrawImage(image, 10, y);
            image.Dispose();

            //ppea.SymbolGraphics.DrawBitmap("\\Program Files\\SignaturePPC\\CapturedSignature1.bmp", 10, 120, image.Width, image.Height);
          

            ppea.HasMorePages = false;

            //RectangleF textRect = new RectangleF(10, 20, 100, 30);
            //Font font = new Font("Tahoma", 11.0F, FontStyle.Regular);
            //ppea.SymbolGraphics.DrawString(this.textBox1.Text, font, brush, textRect);

            //// Print a barcode
            //RectangleF barcodeRect = new RectangleF(10, 60, 100, 30);
            //ppea.SymbolGraphics.DrawBarCode(BarCodeTypes.CODE39, "123456", barcodeRect,
            //                                null, RectangleF.Empty);

            //ppea.HasMorePages = false;

            brush.Dispose();

		}

		private void button2_Click(object sender, System.EventArgs e)
		{
            this.Dispose();
			this.Close();
		}
        private void button1_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
                button1_Click(this, e);
        }

        private void button2_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
                button2_Click(this, e);
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            this.comboBox1.Focus();
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (bInitialScale == true)
            {
                return; // Return if the initial scaling (from scratch)is not complete.
            }

            if (Screen.PrimaryScreen.Bounds.Width > Screen.PrimaryScreen.Bounds.Height) // If landscape orientation
            {
                if (bPortrait != false) // If an orientation change has occured to landscape
                {
                    bPortrait = false; // Set the orientation flag accordingly.
                    bInitialScale = true; // An initial scaling is required due to orientation change.
                    Scale(this); // Scale the GUI.
                }
                else
                {   // No orientation change has occured
                    bSkipMaxLen = true; // Initial scaling is now complete, so skipping the max. length restriction is now possible.
                    Scale(this); // Scale the GUI.
                }
            }
            else
            {
                // Similarly for the portrait orientation...
                if (bPortrait != true)
                {
                    bPortrait = true;
                    bInitialScale = true;
                    Scale(this);
                }
                else
                {
                    bSkipMaxLen = true;
                    Scale(this);
                }
            }
        }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -