1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Printing;
- namespace UAS_MES_NEW.CustomControl.ComBoxWithFocus
- {
- public partial class PrinterCombox : UserControl
- {
- public PrinterCombox()
- {
- InitializeComponent();
- }
- public override string Text
- {
- get
- {
- return PrinterList.Text;
- }
- set
- {
- PrinterList.Text = value;
- }
- }
- private void PrinterCombox_Load(object sender, EventArgs e)
- {
- try
- {
- PrintDocument print = new PrintDocument();
- string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
- foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
- {
- PrinterList.Items.Add(sPrint);
- if (sPrint == sDefault)
- PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
|