using System; using System.Drawing; namespace GoldPrinter { public class PrinterTabStops : IDisposable { private int _cols; public Font Font; public Rectangle Rectangle; private string _text; private string _textConverted; public int Cols { get { return this._cols; } set { this._cols = value; } } public string Text { get { return this._text; } set { this._text = value; string text = this._text; this._textConverted = this.ConvertText(text); } } public PrinterTabStops() { this.Font = new Font("宋体", 10f); this.Rectangle = new Rectangle(0, 0, this.Font.Height, 100); } public PrinterTabStops(string text) : this() { this.Text = text; } public void Draw(Graphics g) { StringFormat stringFormat = new StringFormat(); stringFormat.FormatFlags = StringFormatFlags.NoWrap; float num = (float)(this.Rectangle.Width / this._cols); float[] array = new float[this._cols]; for (int i = 0; i < this._cols; i++) { array[i] = num; } stringFormat.SetTabStops(0f, array); g.DrawString(this._textConverted, this.Font, Brushes.Black, this.Rectangle, stringFormat); } private string ConvertText(string text) { return text.Replace("|", "\t"); } public void Dispose() { this.Font.Dispose(); } } }