SystemSetting_PrinterTest.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Printing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace UAS_MES_NEW.SystemSetting
  11. {
  12. public partial class SystemSetting_PrinterTest : Form
  13. {
  14. public SystemSetting_PrinterTest()
  15. {
  16. InitializeComponent();
  17. }
  18. private void PrintTest_Click(object sender, EventArgs e)
  19. {
  20. PrintDocument print = new PrintDocument();
  21. print.PrinterSettings.PrinterName = PrinterList.Text;
  22. print.PrintPage += Print_PrintPage;
  23. print.Print();
  24. }
  25. private void Print_PrintPage(object sender, PrintPageEventArgs e)
  26. {
  27. Graphics g = e.Graphics;
  28. float leftMargin = 10f; //左边距
  29. SolidBrush myBrush = new SolidBrush(Color.Black);//刷子
  30. float yPosition = 5f;//行定位
  31. Font printFont = new Font("微软雅黑", 20f, FontStyle.Bold);//设置字体
  32. yPosition += printFont.GetHeight(g);//另起一行
  33. g.DrawString("成功连接此打印机", printFont, myBrush, leftMargin, yPosition, new StringFormat());
  34. }
  35. private void Setting_Click(object sender, EventArgs e)
  36. {
  37. PrintDialog printd = new PrintDialog();
  38. printd.PrinterSettings.PrinterName = PrinterList.Text;
  39. printd.ShowDialog();
  40. }
  41. }
  42. }