Title.cs
上传用户:jx_fiona
上传日期:2014-03-08
资源大小:1387k
文件大小:2k
源码类别:

打印编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. namespace GoldPrinter
  4. {
  5. /// <summary>
  6. /// 主标题,默认最多只打印两行文字,可用MaxRows调整,可以用n(VB为VbCrlf)硬换行。在最后一行文字下画强调下划线。
  7. /// 
  8. /// 作 者:长江支流(周方勇)
  9. /// Email:flygoldfish@163.com  QQ:150439795
  10. /// 网 址:www.webmis.com.cn
  11. /// ★★★★★您可以免费使用此程序,但是请您完整保留此说明,以维护知识产权★★★★★
  12. /// 
  13. /// </summary>
  14. public class Title:Caption
  15. {
  16. public Title()
  17. {
  18. this.IsDrawAllPage = true;
  19. this.Font = new Font("黑体",21,FontStyle.Bold); //字体
  20. this.MaxRows = 2;
  21. }
  22. /// <summary>
  23. /// 主标题构造函数
  24. /// </summary>
  25. /// <param name="text">默认最多只打印两行文字,可以用n硬换行。在最后一行文字下画强调下划线</param>
  26. public Title(string text):this()
  27. {
  28. this.Text = text;
  29. }
  30. public override void Draw()
  31. {
  32. base.Draw();
  33. //在最后一行文本下画两根下划线
  34. float x1,x2,y,lineWidth;
  35. lineWidth = this.Rectangle.Width;
  36. //仅找最后一个
  37. int index = this.Text.LastIndexOf("n");
  38. //有硬换行
  39. if (index > 0)
  40. {
  41. string txt = this.Text.Substring(index+1);
  42. lineWidth = this.TextWidth(txt);
  43. }
  44. x1 = (this.PrinterMargins.Width - lineWidth)/2 + this.PrinterMargins.Left + this.MoveX;
  45. y = this.Rectangle.Y + this.Rectangle.Height;
  46. x2 = x1 + lineWidth;
  47. this.Graphics.DrawLine(this.Pen,x1,y-4,x2,y-4);
  48. this.Graphics.DrawLine(this.Pen,x1,y-2,x2,y-2);
  49. // //高再相应的加下划线的高
  50. // this.Rectangle.Height += 2;
  51. }
  52. }//End Class
  53. }//End NameSpace