From c788db5362d5af78f9c895393d0ff14e0c5a5a4e Mon Sep 17 00:00:00 2001 From: lhiven <236881222@qq.com> Date: Thu, 26 Oct 2023 14:19:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96tray=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=87=8F=E5=BA=8F=E5=8F=B7=E4=BB=8E=E5=B7=A6?= =?UTF-8?q?=E5=88=B0=E5=8F=B3=E3=80=81=E4=BB=8E=E5=8F=B3=E5=88=B0=E5=B7=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Controls/RsTray.Designer.cs | 3 - Rs.Controls/RsTray.cs | 137 +++++++++++++-------------------- 2 files changed, 53 insertions(+), 87 deletions(-) diff --git a/Rs.Controls/RsTray.Designer.cs b/Rs.Controls/RsTray.Designer.cs index 3c44af2..45b229d 100644 --- a/Rs.Controls/RsTray.Designer.cs +++ b/Rs.Controls/RsTray.Designer.cs @@ -95,7 +95,6 @@ this.lblStatus.Name = "lblStatus"; this.lblStatus.Size = new System.Drawing.Size(137, 36); this.lblStatus.TabIndex = 2; - this.lblStatus.Text = "IDLE"; this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // label1 @@ -108,7 +107,6 @@ this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(137, 36); this.label1.TabIndex = 1; - this.label1.Text = "label1"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // contextMenuStrip1 @@ -139,7 +137,6 @@ this.禁用ToolStripMenuItem.Name = "禁用ToolStripMenuItem"; this.禁用ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); this.禁用ToolStripMenuItem.Text = "禁用"; - this.禁用ToolStripMenuItem.Visible = false; this.禁用ToolStripMenuItem.Click += new System.EventHandler(this.禁用ToolStripMenuItem_Click); // // RsTray diff --git a/Rs.Controls/RsTray.cs b/Rs.Controls/RsTray.cs index 0deed76..fc352a2 100644 --- a/Rs.Controls/RsTray.cs +++ b/Rs.Controls/RsTray.cs @@ -15,10 +15,11 @@ using System.Xml.Serialization; namespace Rs.Controls { + public enum ESortDir { - Horizontal, - Vertical + LeftToRight, + RightToLeft } public enum ESlotStatus @@ -32,14 +33,26 @@ namespace Rs.Controls public partial class RsTray : UserControl { - private int CurrentSlot { get; set; } = 1; - public string ItemName { get; set; } - public ESortDir SortDir { get; set; } = ESortDir.Horizontal; - public event Action SlotClickEvent; + public string ItemName { get; set; } + + private ESortDir sortDir = ESortDir.LeftToRight; + + public ESortDir SortDir + { + get { return sortDir; } + set { sortDir = value; + UpdateSlotPos(); + } + } + public event Action SlotClickEvent; + #region 是否显示状态 private bool mShowStatus = true; + /// + /// 是否显示状态 + /// public bool ShowStatus { get { return mShowStatus; } @@ -47,6 +60,7 @@ namespace Rs.Controls lblStatus.Visible = mShowStatus; } } + #endregion private string mStatus; @@ -72,15 +86,7 @@ namespace Rs.Controls public void ResetTray() { - CurrentSlot = 1; - } - - public bool IsLastSlot() - { - if(CurrentSlot == RowNum*ColumnNum) { - return true; - } - return false; + } private ESlotStatus _InitSlotStatus = ESlotStatus.Have; @@ -101,20 +107,7 @@ namespace Rs.Controls return null; } - public List GetSlots(ESlotStatus status) - { - List slots = new List(); - foreach (KeyValuePair kv in traySlotsDic) - { - if (kv.Value.SlotStatus == status) - slots.Add(kv.Value); - } - return slots; - } - public bool CanDraw { get; set; } = true; - - private List traySlots = new List(); private Dictionary traySlotsDic = new Dictionary(); private string _HeadText; @@ -245,59 +238,36 @@ namespace Rs.Controls private void InitSlot(ESlotStatus status) { int index = 0; - traySlots.Clear(); traySlotsDic.Clear(); - if (SortDir == ESortDir.Vertical) + for (int r = 0; r < RowNum; r++) { for (int c = 0; c < ColumnNum; c++) { - for (int r = 0; r < RowNum; r++) - { - index++; - TraySlot slot = new TraySlot(); - slot.Index = index; - slot.Row = r; - slot.Column = c; - slot.SlotStatus = status; - traySlots.Add(slot); - traySlotsDic.Add(index, slot); - } - } - } - else - { - for (int r = 0; r < RowNum; r++) - { - for (int c = 0; c < ColumnNum; c++) - { - index++; - TraySlot slot = new TraySlot(); - slot.Index = index; - slot.Row = r; - slot.Column = c; - slot.SlotStatus = status; - traySlots.Add(slot); - traySlotsDic.Add(index, slot); - } + index++; + TraySlot slot = new TraySlot(); + slot.Index = index; + slot.Row = r; + slot.Column = c; + slot.SlotStatus = status; + traySlotsDic.Add(index, slot); } } UpdateSlotPos(); - } public void Fill() { - foreach (TraySlot item in traySlots) + foreach (KeyValuePair kv in traySlotsDic) { - ChangeStatus(item.Index, ESlotStatus.Have); + ChangeStatus(kv.Value.Index, ESlotStatus.Have); } } public void Clear() { - foreach (TraySlot item in traySlots) + foreach (KeyValuePair kv in traySlotsDic) { - ChangeStatus(item.Index, ESlotStatus.NotHave); + ChangeStatus(kv.Value.Index, ESlotStatus.NotHave); } } @@ -315,11 +285,11 @@ namespace Rs.Controls float slotWidth = (this.panel2.Width - LeftSpaceWidth) / ColumnNum; float slotHeight = (this.panel2.Height - TopSpaceHeight) / RowNum; int index = 0; - if (SortDir == ESortDir.Vertical) + if (SortDir == ESortDir.LeftToRight) { - for (int c = 0; c < ColumnNum; c++) + for (int r = 0; r < RowNum; r++) { - for (int r = 0; r < RowNum; r++) + for (int c = 0; c < ColumnNum; c++) { index++; if (traySlotsDic.ContainsKey(index)) @@ -329,7 +299,7 @@ namespace Rs.Controls } } } - else + else if (SortDir == ESortDir.RightToLeft) { for (int r = 0; r < RowNum; r++) { @@ -338,7 +308,7 @@ namespace Rs.Controls index++; if (traySlotsDic.ContainsKey(index)) { - traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * c), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace); + traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * (ColumnNum-1-c)), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace); } } } @@ -367,7 +337,14 @@ namespace Rs.Controls if (r == 0) { //画料盘的列号 - g2.DrawString((c + 1).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5)); + if (SortDir == ESortDir.LeftToRight) + { + g2.DrawString((c+ 1).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5)); + } + else if(SortDir== ESortDir.RightToLeft) + { + g2.DrawString((ColumnNum - c).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5)); + } } if (c == 0) { @@ -435,12 +412,12 @@ namespace Rs.Controls { SelectSlot = null; bool find = false; - foreach (TraySlot slot in this.traySlots) + foreach (KeyValuePair kvSlot in traySlotsDic) { - if (slot.Bound.Contains(e.Location)) + if (kvSlot.Value.Bound.Contains(e.Location)) { find = true; - SelectSlot = slot; + SelectSlot = kvSlot.Value; break; } } @@ -460,11 +437,11 @@ namespace Rs.Controls private void ChangeSlotStatus(ESlotStatus status) { - foreach (TraySlot slot in this.traySlots) + foreach (KeyValuePair kvSlot in traySlotsDic) { - if (drawRect.IntersectsWith(slot.Bound)) + if (drawRect.IntersectsWith(kvSlot.Value.Bound)) { - slot.SlotStatus = status; + kvSlot.Value.SlotStatus = status; } } UpdateSlotPos(); @@ -488,14 +465,6 @@ namespace Rs.Controls { public ESlotStatus SlotStatus { get; set; } = ESlotStatus.Have; - private PointF _Position; - - public PointF Position - { - get { return _Position; } - set { _Position = value; } - } - private int _Index; public int Index @@ -562,7 +531,7 @@ namespace Rs.Controls g.DrawRectangle(Pens.White, Bound.X, Bound.Y, Bound.Width, Bound.Height); if (isShowText) { - g.DrawString((Row + 1) + "-" + (Column + 1), new Font("宋体", 8), new SolidBrush(Color.Yellow), _Bound, sf); + g.DrawString(Index.ToString(), new Font("宋体", 8), new SolidBrush(Color.Yellow), _Bound, sf); } } }