📄 newcontrol.cs
字号:
{
System.Collections.ArrayList _entity = new System.Collections.ArrayList();
public void Add(string theStr)
{
_entity.Add(theStr);
}
public void Add(Image theImage)
{
_entity.Add(theImage);
}
public int Count
{
get
{
return _entity.Count;
}
}
public System.Object this[int Index]
{
set
{
if (Index < _entity.Count)
{
_entity[Index] = value;
}
}
get
{
if (Index < _entity.Count)
{
return _entity[Index];
}
return null;
}
}
}
public class JPM_List : System.Windows.Forms.Control
{
/// <summary>
/// Define const
/// </summary>
public const int FIELD_TYPE_STRING = 0;
public const int FIELD_TYPE_IMAGE = 1;
const int DEFAULT_CPT_TOTOP = 4;
const int DEFAULT_CPT_TOLEFT = 6;
const int DEFAULT_CPT_HEIGHT = 20;
const int DEFAULT_ROW_HEIGHT = 20;
int _heightOfCpt = DEFAULT_CPT_HEIGHT;
int _heightOfRow = DEFAULT_ROW_HEIGHT;
int _cOfDirRows = 0;
int _nowStartRow = 0;
int _nowTier = -1;
bool _dragTier = false;
int _nowChecked = -1;
int _nowScrollY = 0;
int _nowScrollInY = 0;
bool _ifScroll = false;
bool _dragScroll = false;
JPM_List_Entity _nowEntity;
System.Drawing.Image _imageSource = global::NewControl.Resource.BMP_LISTSOURCE;
System.Drawing.Bitmap _bmpUIBuffer;
System.Collections.ArrayList _field = new System.Collections.ArrayList();
System.Collections.ArrayList _fieldType = new System.Collections.ArrayList();
System.Collections.ArrayList _fieldLeft = new System.Collections.ArrayList();
System.Collections.ArrayList _rows = new System.Collections.ArrayList();
public int HeightOfRow
{
set
{
if (value < 1)
{
_heightOfRow = DEFAULT_ROW_HEIGHT;
}
else
{
_heightOfRow = value;
}
}
get
{
return _heightOfRow;
}
}
public int NowCheckedIndex
{
get
{
return _nowChecked;
}
}
public int Count
{
get
{
return _rows.Count;
}
}
public JPM_List_Entity NowCheckedEntity
{
get
{
if (_nowChecked > -1 && _nowChecked < _rows.Count)
{
return (JPM_List_Entity)_rows[_nowChecked];
}
return null;
}
}
protected override void Dispose(bool disposing)
{
if (disposing == true)
{
_imageSource.Dispose();
if (_bmpUIBuffer != null)
{
_bmpUIBuffer.Dispose();
}
}
}
public void AddAnField(string theStr, int theType)
{
if (_fieldLeft.Count == 0)
{
_fieldLeft.Add(0);
}
else
{
_fieldLeft.Add((int)_fieldLeft[_fieldLeft.Count - 1] + (int)this.CreateGraphics().MeasureString((string)_field[_field.Count - 1], this.Font).Width + 6);
}
_field.Add(theStr);
_fieldType.Add(theType);
}
public void AddAnEntity(JPM_List_Entity theEntity)
{
_rows.Add(theEntity);
if (_cOfDirRows < _rows.Count)
{
_ifScroll = true;
}
this.Invalidate();
}
public void AddAnEntityQuiet(JPM_List_Entity theEntity)
{
_rows.Add(theEntity);
if (_cOfDirRows < _rows.Count)
{
_ifScroll = true;
}
}
public void Clear()
{
_rows.Clear();
this.Invalidate();
//this.OnPaint(new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
public void RemoveItemByIndex(int Index)
{
_rows.RemoveAt(Index);
this.Invalidate();
//this.OnPaint(new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
public void RemoveItem(object Item)
{
_rows.Remove(Item);
this.Invalidate();
//this.OnPaint(new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//base.OnPaintBackground(pevent);
}
protected override void OnPaint(PaintEventArgs e)
{
try
{
int t_r, t_rc, t_t, t_tc;
int t_rIndex, t_rTop;
int t_SX, t_NX;
System.Drawing.Pen t_CptPenB = new Pen(Color.White, 3);
System.Drawing.Pen t_CptPenF = new Pen(Color.FromArgb(180, 180, 180));
System.Drawing.SolidBrush t_BBrush = new SolidBrush(Color.Black);
System.Drawing.SolidBrush t_WBrush = new SolidBrush(Color.White);
System.Drawing.SolidBrush t_GBrush = new SolidBrush(Color.FromArgb(222, 222, 222));
System.Drawing.Bitmap t_CptBruImage = new Bitmap(1, 20);
System.Drawing.Graphics t_G = Graphics.FromImage(t_CptBruImage);
t_G.DrawImageUnscaledAndClipped(_imageSource, new Rectangle(0, 0, 1, 20));
System.Drawing.TextureBrush t_CptBrush = new TextureBrush(t_CptBruImage);
if (_bmpUIBuffer == null)
{
if (this.Width > 0 && this.Height > 0)
{
_bmpUIBuffer = new Bitmap(Width, Height);
}
else
{
return;
}
}
_cOfDirRows = (this.Height - DEFAULT_CPT_HEIGHT) / _heightOfRow;
if (_nowStartRow < 0)
{
_nowStartRow = 0;
}
else if (_nowStartRow >= _rows.Count)
{
_nowStartRow = _rows.Count - 1;
}
t_G = Graphics.FromImage(_bmpUIBuffer);
t_G.FillRectangle(t_WBrush, new Rectangle(0, 0, Width, Height));
if (_field.Count > 0)
{
t_tc = _field.Count - 1;
t_G.FillRectangle(t_CptBrush, 0, 0, 2, _heightOfCpt);
for (t_t = 0; t_t < t_tc; t_t++)
{
t_SX = (int)_fieldLeft[t_t];
t_NX = (int)_fieldLeft[t_t + 1];
t_G.FillRectangle(t_CptBrush, t_SX + 2, 0, t_NX - t_SX, _heightOfCpt);
t_G.DrawString((string)_field[t_t], this.Font, t_BBrush, t_SX + DEFAULT_CPT_TOLEFT, DEFAULT_CPT_TOTOP);
t_G.DrawLine(t_CptPenB, t_NX, 1, t_NX, _heightOfCpt - 1);
t_G.DrawLine(t_CptPenF, t_NX, 1, t_NX, _heightOfCpt - 2);
}
t_G.FillRectangle(t_CptBrush, (int)_fieldLeft[t_t] + 2, 0, Width - (int)_fieldLeft[t_t], _heightOfCpt);
t_G.DrawString((string)_field[t_t], this.Font, t_BBrush, (int)_fieldLeft[t_t] + DEFAULT_CPT_TOLEFT, DEFAULT_CPT_TOTOP);
if (_rows.Count > 0)
{
t_rc = _rows.Count - _nowStartRow > _cOfDirRows ? _cOfDirRows : _rows.Count - _nowStartRow;
for (t_r = 0; t_r < t_rc; t_r++)
{
t_rIndex = _nowStartRow + t_r;
_nowEntity = (JPM_List_Entity)_rows[t_rIndex];
t_tc = _nowEntity.Count > t_tc ? t_tc : _nowEntity.Count;
t_rTop = _heightOfCpt + _heightOfRow * t_r;
for (t_t = 0; t_t < t_tc; t_t++)
{
t_SX = (int)_fieldLeft[t_t];
t_NX = (int)_fieldLeft[t_t + 1];
if (t_rIndex == _nowChecked)
{
t_G.FillRectangle(t_GBrush, t_SX, t_rTop + 1, t_NX - t_SX, _heightOfRow - 2);
}
else
{
t_G.FillRectangle(t_WBrush, t_SX, t_rTop, t_NX - t_SX, _heightOfRow);
}
if ((int)_fieldType[t_t] == FIELD_TYPE_STRING)
{
t_G.DrawString((string)_nowEntity[t_t], this.Font, t_BBrush, t_SX + DEFAULT_CPT_TOLEFT, t_rTop + DEFAULT_CPT_TOTOP);
}
else
{
t_G.DrawImage((Image)_nowEntity[t_t], new Rectangle(t_SX + (t_NX - t_SX) / 2, t_rTop + 1, _heightOfRow - 2, _heightOfRow - 2));
}
}
t_SX = (int)_fieldLeft[t_t];
t_NX = this.Width;
if (t_rIndex == _nowChecked)
{
t_G.FillRectangle(t_GBrush, t_SX, t_rTop + 1, t_NX - t_SX, _heightOfRow - 2);
}
else
{
t_G.FillRectangle(t_WBrush, t_SX, t_rTop, t_NX - t_SX, _heightOfRow);
}
if ((int)_fieldType[t_t] == FIELD_TYPE_STRING)
{
t_G.DrawString((string)_nowEntity[t_t], this.Font, t_BBrush, t_SX + DEFAULT_CPT_TOLEFT, t_rTop + DEFAULT_CPT_TOTOP);
}
else
{
t_G.DrawImage((Image)_nowEntity[t_t], new Rectangle(t_SX + (t_NX - t_SX) / 2, t_rTop + 1, _heightOfRow - 2, _heightOfRow - 2));
}
}
}
if (_ifScroll == true)
{
System.Drawing.Bitmap t_SBImage = new Bitmap(15, 1);
(Graphics.FromImage(t_SBImage)).DrawImage(_imageSource, new Rectangle(0, 0, 15, 1), new Rectangle(1, 0, 15, 1), GraphicsUnit.Pixel);
t_r = Width - 15;/*A Temp Use*/
t_t = Height - 15;/*A Temp Use*/
t_G.DrawImage(_imageSource, new Rectangle(t_r, _heightOfCpt, 15, 15), new Rectangle(1, 0, 15, 15), GraphicsUnit.Pixel);
t_G.DrawImage(_imageSource, new Rectangle(t_r, t_t, 15, 15), new Rectangle(1, 15, 15, 15), GraphicsUnit.Pixel);
if (_nowScrollY < _heightOfCpt + 15)
{
_nowScrollY = _heightOfCpt + 15;
}
else if (_nowScrollY > t_t - 34)
{
_nowScrollY = t_t - 34;
}
t_G.DrawImage(t_SBImage, t_r, _heightOfCpt + 15, 15, t_t - _heightOfCpt - 15);
t_G.DrawImage(_imageSource, new Rectangle(t_r + 1, _nowScrollY, 13, 34), new Rectangle(16, 0, 13, 34), GraphicsUnit.Pixel);
}
}
e.Graphics.DrawImageUnscaled(_bmpUIBuffer, 0, 0);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (_dragTier == true)
{
int t_X = e.X;
if (t_X > 5 && t_X < Width - 5)
{
if (_nowTier > 0 && t_X < (int)_fieldLeft[_nowTier - 1] + 5)
{
t_X = (int)_fieldLeft[_nowTier - 1] + 5;
}
int t_n, t_c;
int t_D = t_X - (int)_fieldLeft[_nowTier];
t_c = _fieldLeft.Count;
for (t_n = _nowTier; t_n < t_c; t_n++)
{
_fieldLeft[t_n] = (int)_fieldLeft[t_n] + t_D;
}
}
this.OnPaint(new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
else if (_dragScroll == true)
{
_nowScrollY = e.Y - _nowScrollInY;
_nowStartRow = _field.Count * (_nowScrollY - _heightOfCpt - 15) / (this.Height - _heightOfCpt - 30);
this.OnPaint(new PaintEventArgs(this.CreateGraphics(), this.ClientRectangle));
}
else if (e.Y < _heightOfCpt)
{
int t_n, t_c, t_X;
t_c = _fieldLeft.Count;
for (t_n = 1; t_n < t_c; t_n++)
{
t_X = (int)_fieldLeft[t_n];
if (e.X > t_X - 5 && e.X < t_X + 5)
{
_nowTier = t_n;
this.Cursor = System.Windows.Forms.Cursors.VSplit;
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -