using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Threading;
using Core.LZMes.Client.UIM.comm;
namespace Core.LZMes.Client.UIM.comm
{
class CustomGridView : DataGridView
{
public CustomGridView(Scenes gridType,DataSet ds)
{
//this.Name = gridType.ToString();
this.AllowUserToAddRows = false;
this.AllowUserToDeleteRows = false;
this.AllowUserToResizeColumns = false;
this.AllowUserToResizeRows = false;
this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
this.BorderStyle = BorderStyle.FixedSingle;
this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.ColumnHeadersVisible = false;
this.RowHeadersVisible = false;
this.Width = 200;
this.CellBorderStyle = DataGridViewCellBorderStyle.Single;
this.ReadOnly = true;
this.RowsDefaultCellStyle.SelectionBackColor = Color.LightSteelBlue;
this.RowsDefaultCellStyle.SelectionForeColor = Color.FromArgb(61, 0, 221);
this.RowsDefaultCellStyle.BackColor = Color.LightSteelBlue;
this.BorderStyle = BorderStyle.None;
this.BackgroundColor = Color.LightSteelBlue;
this.ScrollBars = ScrollBars.None;
this.RowTemplate.Height = 15;
this.FontHeight = 10;
this.Font = new Font("宋体", 9);
switch (gridType.ToString())
{
case "PLTCM":
this.DataSource = ds.Tables["pltcm"];
this.Left = 50;
this.Top = 0;
break;
case "CAL":
this.DataSource = ds.Tables["cal"];
this.Left = 570;
this.Top = 320;
break;
case "RCL":
this.DataSource = ds.Tables["rcl"];
this.Left = 710;
this.Top = 150;
break;
}
this.Paint += new PaintEventHandler(myGridView_Paint);
}
///
/// 重绘
///
///
///
void myGridView_Paint(object sender, PaintEventArgs e)
{
int width = 0;
int height = 0;
foreach (DataGridViewColumn cc in this.Columns)
{
width = width + cc.Width;
}
foreach (DataGridViewRow r in this.Rows)
{
bool hasvalue = false;
int cs = this.Columns.Count;
for (int i = 0; i < cs; i++)
{
if (Convert.ToString(r.Cells[i].Value) != "")
{
hasvalue = true;
}
}
if (!hasvalue)
{
r.Height = 0;
}
height = height + r.Height;
}
this.Width = width + 1;
this.Height = height + 1;
}
Int32 flicktime = 0;
///
/// 闪烁
///
///
public void Flicker(Int32 i)
{
flicktime = i;
Thread th = new Thread(DrawRect);
th.Start();
}
bool _StopThread = false;
void DrawRect()
{
try
{
DateTime t1 = DateTime.Now;
bool a = false;
while (!_StopThread)
{
try
{
if (a)
{
Graphics myGraphics = this.CreateGraphics();
Rectangle myRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
Pen myPen = new Pen(Color.Blue, 3F);
myGraphics.DrawRectangle(myPen, myRectangle);
//myGraphics.Dispose();
//myPen.Dispose();
}
else
{
Graphics myGraphics = this.CreateGraphics();
Rectangle myRectangle = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
Pen myPen = new Pen(Color.Red, 3F);
myGraphics.DrawRectangle(myPen, myRectangle);
//myGraphics.Dispose();
//myPen.Dispose();
}
a = !a;
Thread.Sleep(200);
}
catch { }
DateTime t2 = DateTime.Now;
TimeSpan ts = t2 - t1;
if (ts.TotalSeconds > flicktime)
{
_StopThread = true;
}
}
_StopThread = false;
this.BeginInvoke(new MethodInvoker(this.Refresh));
}
catch { }
}
}
}