Esempio n. 1
0
 private void mnuRemove_Click(object sender, EventArgs e)
 {
     if (SelectedIndexs.Count > 0)
     {
         var parts =
             SelectedIndexs
             .Select(i => Folder.PartIndexs[i])
             .ToList();
         string text;
         if (parts.Count == 1)
         {
             text = string.Format("确定把\"{0}\"删除", Database.ImagePartTable[parts[0]].Name);
         }
         else
         {
             text = string.Format("确定把{0}项删除", parts.Count);
         }
         var res =
             MessageBox.Show(
                 text,
                 "确定删除",
                 MessageBoxButtons.OKCancel);
         if (res == DialogResult.OK)
         {
             SelectedIndexs.Clear();
             SelectedItemsChanged(this, null);
             foreach (var part in parts)
             {
                 Remove(part);
             }
             UpdateSize(false);
         }
     }
 }
Esempio n. 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (Folder == null)
            {
                return;
            }

            var g = e.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;
            var foreColorBrush = new SolidBrush(this.ForeColor);
            var halfWhiteBrush = new SolidBrush(Color.FromArgb(96, Color.White));

            var ips =
                from i in _visibleItems
                let index                       = Folder.PartIndexs[i]
                                       let Part = Database.ImagePartTable[index]
                                                  select new { Index = i, Part };

            foreach (var ip in ips)
            {
                var pindex = GetIndex(ip.Index);

                //绘制图形
                var imgrec = GetImageBounds(pindex);
                g.FillRectangle(foreColorBrush, imgrec);
                ip.Part.Image.Draw(g, imgrec);

                //计算文字位置
                var name    = ip.Part.Name;
                var txtrec  = GetTextBounds(pindex);
                var txtsize = g.MeasureString(name, this.Font);
                var pt      = new PointF(
                    txtrec.Left + (txtrec.Width - txtsize.Width) / 2,
                    txtrec.Top - txtsize.Height / 2);

                if (SelectedIndexs.Contains(ip.Index))
                {
                    //选中图形加半透明
                    g.FillRectangle(halfWhiteBrush, imgrec);

                    var rec = new RectangleF(pt, txtsize);
                    rec.Offset(-1, -1);
                    //选中文字白色加蓝色底框
                    g.FillRectangle(Brushes.MediumPurple, rec);
                    g.DrawString(name, this.Font, Brushes.WhiteSmoke, pt);
                }
                else
                {
                    //正常绘制文字
                    g.DrawString(name, this.Font, foreColorBrush, pt);
                }
            }
        }
Esempio n. 3
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            var pindex = GetIndexAtPoint(new Point(e.X, e.Y));
            var index  = GetIndex(pindex);

            if (GetImageBounds(pindex).Contains(e.X, e.Y) && index < Folder.PartIndexs.Count)
            {
                if ((ModifierKeys & Keys.Control) == Keys.Control)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        if (SelectedIndexs.Contains(index))
                        {
                            SelectedIndexs.Remove(index);
                            SelectedItemsChanged(this, null);
                            Invalidate(index);
                        }
                        else
                        {
                            SelectedIndexs.Add(index);
                            SelectedItemsChanged(this, null);
                            Invalidate(index);
                        }
                    }
                }
                else
                {
                    if (!SelectedIndexs.Contains(index))
                    {
                        SelectedIndexs.Clear();
                        SelectedIndexs.Add(index);
                        SelectedItemsChanged(this, null);
                        Invalidate();
                    }
                    if (e.Button == MouseButtons.Right)
                    {
                        contextMenuStrip1.Show(this, new Point(e.X, e.Y));
                    }
                }
            }
            else
            {
                SelectedIndexs.Clear();
                SelectedItemsChanged(this, null);
                Invalidate();
                if (e.Button == MouseButtons.Right)
                {
                    contextMenuStrip1.Show(this, e.X, e.Y);
                }
            }

            base.OnMouseDown(e);
        }
Esempio n. 4
0
        /// <summary>
        /// 根据选中行,读取记录表中的行号和数据,排除多选的情况
        /// </summary>
        /// <param name="popupEvent"></param>
        private GridViewPopupEventArgs SetPopupEvent(int keyIndex)
        {
            GridViewPopupEventArgs popupEvent = new GridViewPopupEventArgs(this);

            switch (dataType)
            {
            case DataEnum.DataTable:
            case DataEnum.DataRows:
            {
                var item = currentPageRowSource.Skip(keyIndex - 1).FirstOrDefault();
                popupEvent.RowIndex  = _dataRowSource.IndexOf(item);
                popupEvent.RowSource = item;
            }
            break;

            case DataEnum.BaseModel:
            {
                var item = currentPageModelSource.Skip(keyIndex - 1).FirstOrDefault();
                popupEvent.RowIndex  = _dataModelSource.IndexOf(item);
                popupEvent.RowSource = item;
            }
            break;

            default:
                break;
            }

            if (!MultiSelect) //单选
            {
                SelectedIndexs.Clear();
                SelectedIndexs.Add(popupEvent.RowIndex);
            }
            else //多选
            {
                //不存在时,选中状态,否则无响应
                if (!SelectedIndexs.Contains(popupEvent.RowIndex))
                {
                    SelectedIndexs.Add(popupEvent.RowIndex);
                }
                else
                {
                    SelectedIndexs.Remove(popupEvent.RowIndex);
                }
            }
            popupEvent.SelectedIndexs = SelectedIndexs;

            return(popupEvent);
        }
Esempio n. 5
0
 public void SelectNull()
 {
     SelectedIndexs.Clear();
     SelectedItemsChanged(this, null);
     this.Invalidate();
 }
Esempio n. 6
0
 public IEnumerable <ImagePart> GetSelectedItems()
 {
     return(SelectedIndexs.Select(i => Database.ImagePartTable[Folder.PartIndexs[i]]));
 }