PrinterCombox.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_LabelMachine.CustomControl
  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. PrintDocument print = new PrintDocument();
  32. string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
  33. foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
  34. {
  35. PrinterList.Items.Add(sPrint);
  36. if (sPrint == sDefault)
  37. PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint);
  38. }
  39. }
  40. private void PrinterList_SelectedIndexChanged(object sender, EventArgs e)
  41. {
  42. PrinterToolTip.SetToolTip(PrinterList, PrinterList.Text);
  43. PrinterToolTip.ShowAlways = true;
  44. }
  45. }
  46. }