namespace IndexFormula.Finance.Win { using System; using System.ComponentModel; using System.Drawing; using System.Runtime.CompilerServices; using System.Windows.Forms; [ToolboxItem(false)] public class StatisticControl : Panel { public bool AutoHeight = true; public bool AutoWidth = true; private Rectangle CloseRect = new Rectangle(4, 4, 10, 10); public int ColumnSpace = 2; public int[] ColumnWidth = new int[] { 80, 80 }; private Container components = null; private Graphics CurrentG; private string Data; public bool EnableMove = true; public Color FrameColor = Color.LightGray; public Brush[] RowBrushs = new Brush[] { Brushes.Khaki, Brushes.Beige, Brushes.WhiteSmoke }; public int RowHeight = 20; public int RowSpace = 2; private string[][] sss; private PointF StartDrag = PointF.Empty; public int TitleHeight = 0x12; public event EventHandler OnHide; public StatisticControl() { this.InitializeComponent(); } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } public bool HasData() { return ((this.Data != null) && (this.Data != "")); } private void HideMe() { base.Visible = false; if (this.OnHide != null) { this.OnHide(this, new EventArgs()); } } private void InitializeComponent() { this.BackColor = SystemColors.Info; this.Cursor = Cursors.Arrow; this.ForeColor = Color.Black; base.Size = new Size(0xd0, 0x158); base.Visible = false; base.MouseUp += new MouseEventHandler(this.StatisticControl_MouseUp); base.Paint += new PaintEventHandler(this.StatisticControl_Paint); base.MouseMove += new MouseEventHandler(this.StatisticControl_MouseMove); base.MouseDown += new MouseEventHandler(this.StatisticControl_MouseDown); } protected override void OnPaintBackground(PaintEventArgs pevent) { if (base.DesignMode || (this.Data == null)) { base.OnPaintBackground(pevent); } } public void PaintTo(Graphics g) { if (base.Visible) { this.PaintTo(g, new Rectangle(base.Location.X, base.Location.Y, base.Size.Width, base.Size.Height - this.TitleHeight), false); } } public void PaintTo(Graphics g, Rectangle Rect, bool ShowTitle) { if ((this.Data == null) || (this.Data == "")) { g.FillRectangle(Brushes.WhiteSmoke, Rect); } else { if (ShowTitle) { g.FillRectangle(Brushes.WhiteSmoke, 0, 0, Rect.Width - 1, this.TitleHeight); g.DrawRectangle(Pens.Black, 0, 0, Rect.Width - 1, this.TitleHeight); g.DrawLine(Pens.Black, this.CloseRect.X, this.CloseRect.Y, this.CloseRect.Right, this.CloseRect.Bottom); g.DrawLine(Pens.Black, this.CloseRect.Right, this.CloseRect.Y, this.CloseRect.Left, this.CloseRect.Bottom); Rect.Y += this.TitleHeight; Rect.Height -= this.TitleHeight; } Pen pen = new Pen(this.FrameColor); Rectangle rect = Rect; rect.Inflate(-1, -1); g.DrawRectangle(new Pen(Color.Black, 2f), rect); rect.Height--; g.SetClip(rect); int bottom = 0; for (int i = 0; i < this.sss.Length; i++) { for (int j = 0; j < 2; j++) { Rectangle rectangle2 = new Rectangle(((this.ColumnSpace + Rect.X) + ((j == 1) ? (this.ColumnWidth[0] + this.ColumnSpace) : 0)) + j, (2 + Rect.Y) + ((this.RowHeight + this.RowSpace) * i), (j == 0) ? (this.ColumnWidth[j] + this.ColumnSpace) : ((rect.Width - this.ColumnWidth[0]) - (this.ColumnSpace * 3)), (this.RowHeight + this.RowSpace) - 1); bottom = rectangle2.Bottom; g.DrawRectangle(pen, rectangle2); g.FillRectangle(this.RowBrushs[i % this.RowBrushs.Length], rectangle2); StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; if (j == 0) { format.Alignment = StringAlignment.Far; } g.DrawString(this.sss[i][j], this.Font, new SolidBrush(this.ForeColor), rectangle2, format); } } g.FillRectangle(Brushes.WhiteSmoke, 2, bottom + 1, base.Width - 4, (base.Height - bottom) - 1); } } public void RefreshData() { this.RefreshData(this.Data); } public void RefreshData(string s) { this.Data = s; if (s != null) { if (s.EndsWith(";")) { s = s.Substring(0, s.Length - 1); } string[] strArray = s.Split(new char[] { ';' }); this.sss = new string[strArray.Length][]; for (int i = 0; i < strArray.Length; i++) { this.sss[i] = strArray[i].Split(new char[] { '=' }); } if (this.CurrentG == null) { this.CurrentG = base.CreateGraphics(); } if (this.AutoWidth) { this.ColumnWidth[0] = -2147483648; this.ColumnWidth[1] = -2147483648; for (int j = 0; j < 2; j++) { for (int k = 0; k < strArray.Length; k++) { SizeF ef = this.CurrentG.MeasureString(this.sss[k][j], this.Font); this.ColumnWidth[j] = Math.Max(this.ColumnWidth[j], (int) ef.Width); } } int num4 = (this.ColumnWidth[0] + this.ColumnWidth[1]) + (this.ColumnSpace * 5); if ((num4 > base.Width) && this.EnableMove) { base.Width = num4; } } if (this.AutoHeight) { this.RowHeight = (int) this.CurrentG.MeasureString(this.sss[0][0], this.Font, 0x3e8).Height; if (this.EnableMove) { base.Height = (((strArray.Length * (this.RowHeight + this.RowSpace)) + this.TitleHeight) + this.RowSpace) + 2; } } base.Invalidate(); } } private void StatisticControl_MouseDown(object sender, MouseEventArgs e) { if (this.CloseRect.Contains(e.X, e.Y)) { this.HideMe(); } else if (this.EnableMove) { this.StartDrag = new PointF((float) e.X, (float) e.Y); } } private void StatisticControl_MouseMove(object sender, MouseEventArgs e) { if (this.StartDrag != PointF.Empty) { base.Location = Point.Round(new PointF((base.Location.X + e.X) - this.StartDrag.X, (base.Location.Y + e.Y) - this.StartDrag.Y)); } } private void StatisticControl_MouseUp(object sender, MouseEventArgs e) { this.StartDrag = PointF.Empty; } private void StatisticControl_Paint(object sender, PaintEventArgs e) { this.PaintTo(e.Graphics, base.ClientRectangle, true); } } }