private void button3_Click(object sender, EventArgs e) { string printerName = null; //comboBox1.SelectedIndex = 0; printerName = comboBox1.SelectedItem.ToString(); if (printerName != null) { Printer.AddCustomPaperSize(printerName, "农行凭证", 241, 115); Printer.SetDefaultPrinter(printerName); } }
private void btnAdd_Click(object sender, EventArgs e) { if (this.cmbPrinter.Text.Trim() != string.Empty && this.txtForm.Text.Trim() != string.Empty && this.txtFormWidth.Text.Trim() != string.Empty && this.txtFormHeight.Text.Trim() != string.Empty) { System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument(); pd.PrinterSettings.PrinterName = this.cmbPrinter.Text.Trim(); bool bolExist = false; foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes) { if (ps.PaperName == this.txtForm.Text.Trim()) { bolExist = true; break; } } pd.Dispose(); if (bolExist) { System.Windows.Forms.MessageBox.Show("The added form already exists!Pls delete it first!"); return; } Printer.AddCustomPaperSize(this.cmbPrinter.Text, this.txtForm.Text.Trim(), System.Convert.ToSingle(this.txtFormWidth.Text.Trim()) * 10, System.Convert.ToSingle(this.txtFormHeight.Text.Trim()) * 10); this.GetForms(); this.cmbForm.Text = this.txtForm.Text.Trim(); } else { decimal decOut = 0; if (this.cmbPrinter.Text.Trim() == string.Empty) { this.epError.SetError(this.cmbPrinter, "Pls select a printer!"); } if (this.txtForm.Text.Trim() == string.Empty) { this.epError.SetError(this.txtForm, "Pls set a proper form!"); } if (this.txtFormHeight.Text.Trim() == string.Empty || !System.Decimal.TryParse(this.txtFormHeight.Text.Trim(), out decOut)) { this.epError.SetError(this.txtFormHeight, "Pls set the value of pageheight!"); } if (this.txtFormWidth.Text.Trim() == string.Empty || !System.Decimal.TryParse(this.txtFormWidth.Text.Trim(), out decOut)) { this.epError.SetError(this.txtFormWidth, "Pls set the value of pagewidth!"); } } }