PrinterCombox.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Drawing.Printing;
  10. namespace UAS_MES_NEW.CustomControl.ComBoxWithFocus
  11. {
  12. public partial class PrinterCombox : UserControl
  13. {
  14. public PrinterCombox()
  15. {
  16. InitializeComponent();
  17. }
  18. public override string Text
  19. {
  20. get
  21. {
  22. return PrinterList.Text;
  23. }
  24. set
  25. {
  26. PrinterList.Text = value;
  27. }
  28. }
  29. private void PrinterCombox_Load(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. PrintDocument print = new PrintDocument();
  34. string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
  35. foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
  36. {
  37. PrinterList.Items.Add(sPrint);
  38. if (sPrint == sDefault)
  39. PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint);
  40. }
  41. }
  42. catch (Exception ex)
  43. {
  44. MessageBox.Show(ex.Message);
  45. }
  46. }
  47. }
  48. }