123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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_LabelMachine.CustomControl
- {
- public partial class PrinterCombox : UserControl
- {
- public PrinterCombox()
- {
- InitializeComponent();
- }
- public delegate void OnSelectIndexChange(object sender, EventArgs e);
- public event OnSelectIndexChange UserOnSelectIndexChange;
- public override string Text
- {
- get
- {
- return PrinterList.Text;
- }
- set
- {
- PrinterList.Text = value;
- }
- }
- bool Loading = true;
- private void PrinterCombox_Load(object sender, EventArgs e)
- {
- 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);
- }
- Loading = false;
- }
- private void PrinterList_SelectedIndexChanged(object sender, EventArgs e)
- {
- if(!Loading)
- UserOnSelectIndexChange.Invoke(sender, e);
- }
- }
- }
|