2022-12-27 17:33:33 +08:00

127 lines
2.4 KiB
C#

using System;
using System.Drawing;
namespace GoldPrinter
{
public class Top : Printer
{
protected DrawGrid mdrawGrid;
protected string _text;
protected object _dataSource;
public string Text
{
get
{
return this._text;
}
set
{
this._text = value;
this.SetText(this._text);
}
}
public object DataSource
{
get
{
return this._dataSource;
}
set
{
if (value != null)
{
if (value.GetType().ToString() == "System.String")
{
this.Text = (string)value;
}
else if (value.GetType().ToString() == "System.String[]")
{
string text = "";
string[] array = (string[])value;
if (array.Length > 0)
{
for (int i = 0; i < array.Length; i++)
{
text = text + "|" + array[i];
}
text = text.Substring(1);
this.Text = text;
}
else
{
this.Text = "";
}
}
}
else
{
this._dataSource = null;
}
}
}
public override int Height
{
get
{
return this.mdrawGrid.Rows * this.mdrawGrid.PreferredRowHeight;
}
}
public Top()
{
this.IsDrawAllPage = true;
this._text = "";
this.mdrawGrid = new DrawGrid();
this.mdrawGrid.ColsAlignString = "LCR";
this.mdrawGrid.Border = GridBorderFlag.None;
this.mdrawGrid.Line = GridLineFlag.None;
this.mdrawGrid.Merge = GridMergeFlag.None;
this.Font = new Font("宋体", 11f);
this.mdrawGrid.PreferredRowHeight = this.Font.Height;
this.mdrawGrid.Initialize(1, 3);
}
public virtual void SetText(string text)
{
this._text = text;
this.SetText(text, '|');
}
public virtual void SetText(string text, char split)
{
this._text = text;
string[] array = text.Split(new char[]
{
split
});
if (array.Length > 0)
{
this.mdrawGrid.SetText(0, 0, array[0]);
}
if (array.Length > 1)
{
this.mdrawGrid.SetText(0, 1, array[1]);
}
if (array.Length > 2)
{
this.mdrawGrid.SetText(0, 2, array[2]);
}
}
public override void Draw()
{
base.Draw();
this.mdrawGrid.Rectangle = new Rectangle(base.Rectangle.X + base.MoveX, base.Rectangle.Y + base.MoveY, base.Rectangle.Width, base.Rectangle.Height);
this.mdrawGrid.Graphics = base.Graphics;
this.mdrawGrid.Width = this.mdrawGrid.Rectangle.Width;
this.mdrawGrid.ColsWidth = this.mdrawGrid.GetAverageColsWidth();
this.mdrawGrid.Draw();
}
}
}