123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WFtpClient
- {
- public partial class UCGroupItems : Control
- {
- public UCGroupItems()
- {
- this.Padding = new Padding(0, 24, 0, 0);
- this.Dock = DockStyle.Top;
- this.Width = 900;
- this.Height = 50;
- this.Paint += UCGroupItems_Paint;
- this.MouseMove += UCGroupItems_MouseMove;
- this.MouseDown += UCGroupItems_MouseDown;
- this.MouseUp += UCGroupItems_MouseUp;
- this.MouseLeave += UCGroupItems_MouseLeave;
- this._GroupMark ="Group_" +GenerateId().ToString();
- this.BackColor = Color.White;
- }
- void UCGroupItems_MouseLeave(object sender, EventArgs e)
- {
- foreach (UCItems ucItem in this.UCItemsList)
- {
- if (ucItem.LbItemTextBrush != Brushes.Black)
- {
- ucItem.LbItemTextBrush = Brushes.Black;
- this.Invalidate(ucItem.GetLbItemTextRectangle());
- break;
- }
-
- }
- }
- public UCGroupItems(string groupName, string groupMark=null)
- : this()
- {
- this._GroupNameText = groupName;
- if (groupMark != null && groupMark.Trim().Length>0)
- {
- this._GroupMark = groupMark;
- }
-
- }
- /// <summary>
- /// 全局ID
- /// </summary>
- /// <returns></returns>
- public static long GenerateId()
- {
- byte[] buffer = Guid.NewGuid().ToByteArray();
- return BitConverter.ToInt64(buffer, 0);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="e"></param>
- public delegate void EventGroupItemClickHandler(EventGroupItemClick e);
- /// <summary>
- /// 申明委托
- /// </summary>
- /// <param name="e"></param>
- /// <returns></returns>
- public delegate void EventItemClickHandler(EventItemClick e);
- /// <summary>
- /// UCItemOperating事件
- /// </summary>
- public event EventItemClickHandler UCItemOperatingClick;
- /// <summary>
- /// UCItemDelete事件
- /// </summary>
- public event EventItemClickHandler UCItemDeleteClick;
- ///<summary>
- /// GroupUCItemOperating事件
- /// </summary>
- public event EventGroupItemClickHandler GroupUCItemOperatingClick;
- /// <summary>
- /// GroupUCItemDelete事件
- /// </summary>
- public event EventGroupItemClickHandler GroupUCItemDeleteClick;
- void UCGroupItems_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.X > this.Width - 95)
- {
- if (this.ContainsOperating(e.X, e.Y))
- {
- this.GroupLinkOperatingBrush = Brushes.DodgerBlue;
- this.Invalidate(getOperatingRectangle());
- if (this.GroupUCItemOperatingClick != null)
- {
- this.GroupUCItemOperatingClick(new EventGroupItemClick(this));
- }
- }
- else if (this.ContainsDelete(e.X, e.Y))
- {
- this.GroupLinkDeleteBrush = Brushes.DodgerBlue;
- this.Invalidate(getDeleteRectangle());
- if (this.GroupUCItemDeleteClick != null)
- {
- this.GroupUCItemDeleteClick(new EventGroupItemClick(this));
- }
- }
- foreach (UCItems ucItem in this.UCItemsList)
- {
- if (ucItem.ContainsOperating(e.X, e.Y))
- {
- ucItem.LinkOperatingBrush = Brushes.RoyalBlue;
- this.Invalidate(ucItem.GetOperatingRectangle());
- if (this.UCItemOperatingClick != null)
- {
- this.UCItemOperatingClick(new EventItemClick(ucItem));
- }
- break;
- }
- else if (ucItem.ContainsDelete(e.X, e.Y))
- {
- ucItem.LinkDeleteBrush = Brushes.RoyalBlue;
- this.Invalidate(ucItem.GetDeleteRectangle());
- if (this.UCItemDeleteClick != null)
- {
- this.UCItemDeleteClick(new EventItemClick(ucItem));
- }
- break;
- }
- }
- }
- }
- void UCGroupItems_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.X > this.Width - 95)
- {
- if (this.ContainsOperating(e.X, e.Y))
- {
- this.GroupLinkOperatingBrush = Brushes.Red;
- this.Invalidate(getOperatingRectangle());
- }
- else if (this.ContainsDelete(e.X, e.Y))
- {
- this.GroupLinkDeleteBrush = Brushes.Red;
- this.Invalidate(getDeleteRectangle());
- }
- foreach (UCItems ucItem in this.UCItemsList)
- {
- if (ucItem.ContainsOperating(e.X, e.Y))
- {
- ucItem.LinkOperatingBrush = Brushes.Red;
- this.Invalidate(ucItem.GetOperatingRectangle());
- break;
- }
- else if (ucItem.ContainsDelete(e.X, e.Y))
- {
- ucItem.LinkDeleteBrush = Brushes.Red;
- this.Invalidate(ucItem.GetDeleteRectangle());
- break;
- }
- }
- }
- }
- void UCGroupItems_MouseMove(object sender, MouseEventArgs e)
- {
- if (this.ContainsOperating(e.X, e.Y)
- || this.ContainsDelete(e.X, e.Y))
- {
- this.Cursor = Cursors.Hand;
- }
- else
- {
- if (this.UCItemsList.Count > 0)
- {
- bool isContains = false;
- foreach (UCItems ucItem in this.UCItemsList)
- {
- if (ucItem.ContainsOperating(e.X, e.Y)
- || ucItem.ContainsDelete(e.X, e.Y))
- {
- isContains = true;
- break;
- }
- else if (ucItem.ContainsLbItemText(e.X, e.Y))
- {
- if (ucItem.LbItemTextBrush != Brushes.Red)
- {
- ucItem.LbItemTextBrush = Brushes.Red;
- this.Invalidate(ucItem.GetLbItemTextRectangle());
- }
-
- }
- else
- {
- if (ucItem.LinkOperatingBrush != Brushes.RoyalBlue)
- {
- ucItem.LinkOperatingBrush = Brushes.RoyalBlue;
- this.Invalidate(ucItem.GetOperatingRectangle());
- }
- if (ucItem.LinkDeleteBrush != Brushes.RoyalBlue)
- {
- ucItem.LinkDeleteBrush = Brushes.RoyalBlue;
- this.Invalidate(ucItem.GetDeleteRectangle());
- }
- if (ucItem.LbItemTextBrush != Brushes.Black)
- {
- ucItem.LbItemTextBrush = Brushes.Black;
- this.Invalidate(ucItem.GetLbItemTextRectangle());
- }
-
- }
- }
- if (isContains)
- {
- this.Cursor = Cursors.Hand;
- }
- else {
- this.Cursor = Cursors.Default;
- }
- }
- else
- {
- this.Cursor = Cursors.Default;
- }
- }
- }
- Rectangle getOperatingRectangle()
- {
- return new Rectangle(this.Width - 95, 0, 35, 24);
- }
- Rectangle getDeleteRectangle()
- {
- return new Rectangle(this.Width - 52, 0, 35, 24);
- }
- bool ContainsOperating(int x, int y)
- {
- return getOperatingRectangle().Contains(x, y);
- }
- bool ContainsDelete(int x, int y)
- {
- return getDeleteRectangle().Contains(x, y);
- }
- void UCGroupItems_Paint(object sender, PaintEventArgs e)
- {
- #region 画组名称
- Pen p = new Pen(Brushes.WhiteSmoke);
- p.Width = 24;
- e.Graphics.DrawLine(p, new Point(0, 12), new Point(this.Width, 12));
- e.Graphics.DrawString(this.GroupNameText, this.GroupNameFont, Brushes.Black, new PointF(0, 2));
- p.Dispose();
- #endregion
- this.DrawOperatingButton(e.Graphics, this.GroupLinkOperatingBrush);
- this.DrawDeleteButton(e.Graphics, this.GroupLinkDeleteBrush);
- for (int i = 0; i < UCItemsList.Count; i++)
- {
- UCItems ucItem = UCItemsList[i];
- ucItem.SetIndex(i);
- ucItem.Width = this.Width;
- int y = 24 + ucItem.Height * i;
- e.Graphics.DrawString(ucItem.LbItemText, ucItem.LbItemTextFont, ucItem.LbItemTextBrush, new PointF(0, y + 3));
- Pen pBack = new Pen(Brushes.GhostWhite);
- pBack.Width = 26f;
- e.Graphics.DrawLine(pBack, new Point(this.Width - (100 + ucItem.PlProgressWidth), y + 13), new Point(this.Width - 100, y + 13));
- pBack.Color = Color.Green;
- int ProgressValue = this.Width - 100 - ucItem.PlProgressWidth + (ucItem.UCProgressValue*2);
- if (ProgressValue >= this.Width - 100)
- {
- ProgressValue = this.Width - 100;
- }
- e.Graphics.DrawLine(pBack, new Point(this.Width - (100 + ucItem.PlProgressWidth), y + 13), new Point(ProgressValue, y + 13));
- pBack.Dispose();
- e.Graphics.DrawString(ucItem.UCProgressValue.ToString() + "%", ucItem.LbItemTextFont, Brushes.Black, new PointF(this.Width - (100 + ucItem.PlProgressWidth) + ucItem.PlProgressWidth / 2 - 10, y + 3));
- ucItem.DrawOperatingButton(e.Graphics, ucItem.LinkOperatingBrush);
- ucItem.DrawDeleteButton(e.Graphics, ucItem.LinkDeleteBrush);
- Pen pline = new Pen(Brushes.LightGray);
- pline.Width = 1f;
- e.Graphics.DrawLine(pline, new Point(0, y + 26), new Point(this.Width, y + 26));
- pline.Dispose();
- }
- e.Graphics.Dispose();
- }
- void DrawOperatingButton(Graphics g, Brush b = null)
- {
- if (b == null)
- {
- b = Brushes.DodgerBlue;
- }
- g.DrawString(this.GroupLinkOperatingText, this.GroupOperatingFont, b, new PointF(this.Width - 90, 3));
- }
- void DrawDeleteButton(Graphics g, Brush b = null)
- {
- if (b == null)
- {
- b = Brushes.DodgerBlue;
- }
- g.DrawString(this.GroupLinkDeleteText, this.GroupOperatingFont, b, new PointF(this.Width - 50, 3));
- }
- string _GroupLinkOperatingText = "开始";
- /// <summary>
- /// 组LinkOperating文本
- /// </summary>
- public string GroupLinkOperatingText
- {
- get { return _GroupLinkOperatingText; }
- set { _GroupLinkOperatingText = value; }
- }
- string _GroupLinkDeleteText = "删除";
- /// <summary>
- /// 组LinkDelete 文本
- /// </summary>
- public string GroupLinkDeleteText
- {
- get { return _GroupLinkDeleteText; }
- set { _GroupLinkDeleteText = value; }
- }
- Brush GroupLinkOperatingBrush = Brushes.DodgerBlue;
- Brush GroupLinkDeleteBrush = Brushes.DodgerBlue;
- Font GroupOperatingFont = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- /// <summary>
- /// 组名字体
- /// </summary>
- Font GroupNameFont = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- string _GroupMark = "";
- /// <summary>
- /// 组标识
- /// </summary>
- public string GroupMark
- {
- get { return _GroupMark; }
- set { _GroupMark = value; }
- }
- string _GroupNameText = "组名";
- /// <summary>
- /// 组标题文本
- /// </summary>
- public string GroupNameText
- {
- get { return _GroupNameText; }
- set { _GroupNameText = value; }
- }
- List<UCItems> _UCItemsList = new List<UCItems>();
- public List<UCItems> UCItemsList
- {
- get { return _UCItemsList; }
- }
- public void Add(UCItems item)
- {
- item.ParentContainer = this;
- this._UCItemsList.Add(item);
- this.Height = 24 + this._UCItemsList.Count * item.Height;
- //this.Refresh();
- }
- public void Remove(UCItems item)
- {
- this._UCItemsList.Remove(item);
- this.Height = 24 + this._UCItemsList.Count * item.Height;
- this.Invalidate();
- }
- }
- public class UCItems
- {
- public UCItems()
- {
- }
- public UCItems(string itemText, int progressValue = 0)
- : this()
- {
- this.UCProgressValue = progressValue;
- this.LbItemText = itemText;
- SetLbProgressValue(progressValue);
- }
- UCGroupItems _ParentContainer;
- /// <summary>
- /// 父容器
- /// </summary>
- public UCGroupItems ParentContainer
- {
- get { return _ParentContainer; }
- set { _ParentContainer = value; }
- }
- int _Width = 900;
- public int Width
- {
- get { return _Width; }
- set { _Width = value; }
- }
- int _Height = 28;
- public int Height
- {
- get { return _Height; }
- set { _Height = value; }
- }
- int _index = 0;
- /// <summary>
- /// 索引
- /// </summary>
- public int Index
- {
- get { return _index; }
- }
- /// <summary>
- /// 设置索引
- /// </summary>
- /// <param name="index"></param>
- public void SetIndex(int index)
- {
- this._index = index;
- }
- public int Y
- {
- get { return 24 + this.Height * this._index; }
- }
- public Rectangle GetLbProgressValueRectangle()
- {
- return new Rectangle(this.Width - (100 + this.PlProgressWidth), Y, 200,26);
- }
- public Rectangle GetLbItemTextRectangle()
- {
- return new Rectangle(0, Y + 1, this.Width - 300, 25);
- }
- public bool ContainsLbItemText(int x, int y)
- {
- return GetLbItemTextRectangle().Contains(x, y);
- }
- public Rectangle GetOperatingRectangle()
- {
- return new Rectangle(this.Width - 95, Y + 1, 35, 24);
- }
- public Rectangle GetDeleteRectangle()
- {
- return new Rectangle(this.Width - 52, Y + 1, 35, 24);
- }
- public bool ContainsOperating(int x, int y)
- {
- return GetOperatingRectangle().Contains(x, y);
- }
- public bool ContainsDelete(int x, int y)
- {
- return GetDeleteRectangle().Contains(x, y);
- }
- public void DrawOperatingButton(Graphics g, Brush b = null)
- {
- if (b == null)
- {
- b = Brushes.RoyalBlue;
- }
- g.DrawString(LinkOperatingText, this.OperatingFont, b, new PointF(this.Width - 90, Y + 3));
- }
- public void DrawDeleteButton(Graphics g, Brush b = null)
- {
- if (b == null)
- {
- b = Brushes.RoyalBlue;
- }
- g.DrawString(LinkDeleteText, this.OperatingFont, b, new PointF(this.Width - 50, Y + 3));
- }
- string _LinkOperatingText = "开始";
- /// <summary>
- /// 项 LinkOperatingText 文本
- /// </summary>
- public string LinkOperatingText
- {
- get { return _LinkOperatingText; }
- set { _LinkOperatingText = value; }
- }
- string _LinkDeleteText = "删除";
- /// <summary>
- /// 项 LinkDeleteText 文本
- /// </summary>
- public string LinkDeleteText
- {
- get { return _LinkDeleteText; }
- set { _LinkDeleteText = value; }
- }
- public Brush LinkOperatingBrush = Brushes.RoyalBlue;
- public Brush LinkDeleteBrush = Brushes.RoyalBlue;
- public Font OperatingFont = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- public Font LbItemTextFont = new Font("微软雅黑", 10);
- public Brush LbItemTextBrush = Brushes.Black;
- string _LbItemText = "新上传任务";
- /// <summary>
- ///
- /// </summary>
- public string LbItemText
- {
- get { return _LbItemText; }
- set { _LbItemText = value; }
- }
- public void SetLbProgressValue(int progressValue)
- {
- if (this.UCProgressValue != progressValue)
- {
- this.UCProgressValue = progressValue;
- if (this.ParentContainer != null)
- {
- this.ParentContainer.Invalidate(this.GetLbProgressValueRectangle());
- // this.ParentContainer.Invalidate();
- }
- }
- }
- int _UCProgressValue = 0;
- /// <summary>
- /// 进度值 % 百分比
- /// </summary>
- public int UCProgressValue
- {
- get { return _UCProgressValue; }
- set { _UCProgressValue = value; }
- }
- int _PlProgressWidth = 200;
- /// <summary>
- /// 进度条宽度
- /// </summary>
- public int PlProgressWidth
- {
- get { return _PlProgressWidth; }
- set { _PlProgressWidth = value; }
- }
- }
- public class EventGroupItemClick : EventArgs
- {
- public EventGroupItemClick(UCGroupItems gItem)
- {
- this.ucGroupItem = gItem;
- }
- UCGroupItems ucGroupItem;
- public UCGroupItems UcGroupItem
- {
- get { return ucGroupItem; }
- set { ucGroupItem = value; }
- }
- }
- public class EventItemClick : EventArgs
- {
- public EventItemClick(UCItems item) {
- this.ucItem = item;
- }
- UCItems ucItem;
- public UCItems UcItem
- {
- get { return ucItem; }
- set { ucItem = value; }
- }
- }
- }
|