internal void RenderItem(ShengListViewItem item) { if (Suspend == false) { _layoutManager.RenderItem(this.CreateGraphics(), item); } }
/// <summary> /// 判断指定的项是否处于可见状态 /// </summary> /// <param name="item"></param> /// <returns></returns> public ShengListViewItemVisibility IsItemVisible(ShengListViewItem item) { int itemIndex = _imageListView.Items.IndexOf(item); if (_imageListView.Items.Count == 0) { return(ShengListViewItemVisibility.NotVisible); } if (itemIndex < 0 || itemIndex > _imageListView.Items.Count - 1) { return(ShengListViewItemVisibility.NotVisible); } if (itemIndex < _firstPartiallyVisible || itemIndex > _lastPartiallyVisible) { return(ShengListViewItemVisibility.NotVisible); } else if (itemIndex >= _firstVisible && itemIndex <= _lastVisible) { return(ShengListViewItemVisibility.Visible); } else { return(ShengListViewItemVisibility.PartiallyVisible); } }
/// <summary> /// 双击项 /// </summary> /// <param name="item"></param> internal void OnItemDoubleClick(ShengListViewItem item) { if (ItemDoubleClick != null) { ItemDoubleClick(this, new ShengListViewItemDoubleClickEventArgs(item)); } }
/// <summary> /// 绘制项的内容 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> /// <param name="item"></param> internal virtual void DrawItemContent(Graphics g, Rectangle bounds, ShengListViewItem item) { //显示debug信息 string debugInfo = item.Index + Environment.NewLine + bounds.ToString() + Environment.NewLine + item.State.ToString(); g.DrawString(debugInfo, SystemFonts.DefaultFont, Brushes.Black, bounds); }
/// <summary> /// 绘制项 /// </summary> /// <param name="g"></param> /// <param name="item"></param> /// <param name="state"></param> /// <param name="bounds"></param> internal virtual void DrawItem(Graphics g, ShengListViewItem item) { Rectangle bounds = LayoutManager.GetItemBounds(item); g.SetClip(bounds); DrawItemBackground(g, bounds); Rectangle backgroundRect = bounds; backgroundRect.Width -= 1; backgroundRect.Height -= 1; // Paint background Selected if ((LayoutManager.Focused && ((item.State & ShengListViewItemState.Selected) == ShengListViewItemState.Selected)) || (LayoutManager.Focused == false && ((item.State & ShengListViewItemState.Selected) == ShengListViewItemState.Selected) && ((item.State & ShengListViewItemState.Hovered) == ShengListViewItemState.Hovered))) { using (Brush bSelected = new LinearGradientBrush(backgroundRect, Theme.SelectedColorStart, Theme.SelectedColorEnd, LinearGradientMode.Vertical)) { // ImageListViewUtility.FillRoundedRectangle(g, bSelected, bounds, 4); g.FillPath(bSelected, DrawingTool.RoundedRect(backgroundRect, _radius)); } } // Paint background unfocused else if (LayoutManager.Focused == false && ((item.State & ShengListViewItemState.Selected) == ShengListViewItemState.Selected)) { using (Brush bGray64 = new LinearGradientBrush(backgroundRect, Theme.UnFocusedColorStart, Theme.UnFocusedColorEnd, LinearGradientMode.Vertical)) { // ImageListViewUtility.FillRoundedRectangle(g, bGray64, bounds, 4); g.FillPath(bGray64, DrawingTool.RoundedRect(backgroundRect, _radius)); } } // Paint background Hovered //如果正处于框选状态,不绘制Hover状态,减小闪烁 if (LayoutManager.MouseSelecting == false && (item.State & ShengListViewItemState.Hovered) == ShengListViewItemState.Hovered) { using (Brush bHovered = new LinearGradientBrush(backgroundRect, Theme.HoverColorStart, Theme.HoverColorEnd, LinearGradientMode.Vertical)) { // ImageListViewUtility.FillRoundedRectangle(g, bHovered, bounds, 4); g.FillPath(bHovered, DrawingTool.RoundedRect(backgroundRect, _radius)); } } DrawItemBorder(g, bounds, item); // Focus rectangle if (LayoutManager.Focused && ((item.State & ShengListViewItemState.Focused) == ShengListViewItemState.Focused)) { ControlPaint.DrawFocusRectangle(g, bounds); } DrawItemContent(g, bounds, item); }
public void RenderItem(Graphics g, ShengListViewItem item) { if (LayoutManager.Suspend) { return; } if (LayoutManager.IsItemVisible(item) == ShengListViewItemVisibility.NotVisible) { return; } DrawItem(g, item); }
protected override void OnMouseDoubleClick(MouseEventArgs e) { if (ItemDoubleClick != null) { ShengListViewHitInfo hitInfo = _layoutManager.HitTest(e.Location); if (hitInfo.ItemHit) { ShengListViewItem item = Items[hitInfo.ItemIndex]; OnItemDoubleClick(item); } } base.OnMouseDoubleClick(e); }
/// <summary> /// 绘制项的边框 /// </summary> /// <param name="g"></param> /// <param name="bounds"></param> internal virtual void DrawItemBorder(Graphics g, Rectangle bounds, ShengListViewItem item) { if (item.Hovered || item.Selected) { Rectangle backgroundRect = bounds; backgroundRect.Width -= 1; backgroundRect.Height -= 1; using (Pen pWhite128 = new Pen(Color.FromArgb(128, Theme.ItemBorderColor))) { // ImageListViewUtility.DrawRoundedRectangle(g, pWhite128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, _radius); g.DrawPath(pWhite128, DrawingTool.RoundedRect(backgroundRect, _radius)); } } }
internal override void DrawItemContent(Graphics g, Rectangle bounds, ShengListViewItem item) { string header = LayoutManager.GetItemText(item.Value); if (String.IsNullOrEmpty(header)) { return; } if (_headerHeightInited == false) { SizeF headerSize = g.MeasureString(header, Theme.ItemHeaderFont); _headerHeight = (int)Math.Ceiling(headerSize.Height); _headerHeightInited = true; } #region 绘制文本 _headerBounds = new Rectangle(); _headerBounds.X = _itemPadding.Width; _headerBounds.Y = _itemPadding.Height; _headerBounds.Width = bounds.Width; _headerBounds.Height = _headerHeight; _headerBounds.Offset(bounds.Location); if (String.IsNullOrEmpty(header) == false) { using (SolidBrush brush = new SolidBrush(Theme.ItemHeaderColor)) { g.DrawString(header, Theme.ItemHeaderFont, brush, _headerBounds, _itemHeaderStringFormat); } } #endregion }
internal override void DrawItemContent(Graphics g, Rectangle bounds, ShengListViewItem item) { string header = LayoutManager.GetItemText(item.Value); //如果header为空则不南要绘制内容了 if (String.IsNullOrEmpty(header)) { return; } string description = null; if (LayoutManager.ContainerExtendMember(ShengListViewDescriptiveMembers.DescriptioinMember)) { description = LayoutManager.GetItemText(item.Value, LayoutManager.GetExtendMember(ShengListViewDescriptiveMembers.DescriptioinMember)); } if (_headerHeightInited == false) { _headerFont = new Font(Theme.ItemHeaderFont, FontStyle.Bold); SizeF headerSize = g.MeasureString(header, _headerFont); _headerHeight = (int)Math.Ceiling(headerSize.Height); _headerHeightInited = true; } #region 绘制文本 Rectangle _headerBounds = new Rectangle(); _headerBounds.X = _itemPadding.Width; _headerBounds.Y = _itemPadding.Height;//LayoutManager.ItemSize - _headerHeight - _itemPadding.Height; _headerBounds.Width = bounds.Width; _headerBounds.Height = _headerHeight; Rectangle _descriptionBounds = new Rectangle(); _descriptionBounds.X = _itemPadding.Width; _descriptionBounds.Y = _headerBounds.Y + _headerBounds.Height + _itemPadding.Height; _descriptionBounds.Width = bounds.Width; _descriptionBounds.Height = _headerHeight; //注意,offset必须在最后,如果先offset了_headerBounds,再带入_headerBounds来计算_descriptionBounds //就不对了 _headerBounds.Offset(bounds.Location); _descriptionBounds.Offset(bounds.Location); if (String.IsNullOrEmpty(header) == false) { using (SolidBrush brush = new SolidBrush(Theme.ItemHeaderColor)) { g.DrawString(header, _headerFont, brush, _headerBounds, _itemHeaderStringFormat); } } if (String.IsNullOrEmpty(description) == false) { using (SolidBrush brush = new SolidBrush(Theme.ItemDescriptioniColor)) { g.DrawString(description, Theme.ItemHeaderFont, brush, _descriptionBounds, _itemHeaderStringFormat); } } #endregion }
public void OnKeyDown(KeyEventArgs e) { // If the shift key or the control key is pressed and there is no focused item // set the first item as the focused item. if ((ShiftKey || ControlKey) && _imageListView.Items.Count != 0 && _imageListView.FocusedItem == null) { _imageListView.Items[0].Focused = true; } ShengListViewItem currentFocusedItem = _imageListView.FocusedItem; if (_imageListView.Items.Count != 0) { int index = 0; if (currentFocusedItem != null) { index = currentFocusedItem.Index; } int newindex = ApplyNavKey(index, e.KeyCode); if (index != newindex) { #region 根据新index做选择 if (ControlKey) { // Just move the focus } else if (_imageListView.AllowMultiSelection && ShiftKey) { int startIndex = 0; int endIndex = 0; List <ShengListViewItem> selectedItems = _imageListView.GetSelectedItems(); if (selectedItems.Count != 0) { startIndex = selectedItems[0].Index; endIndex = selectedItems[selectedItems.Count - 1].Index; _imageListView.ClearSelect(); } if (index == startIndex) { startIndex = newindex; } else if (index == endIndex) { endIndex = newindex; } for (int i = Math.Min(startIndex, endIndex); i <= Math.Max(startIndex, endIndex); i++) { _imageListView.Items[i].Selected = true; } } else { _imageListView.ClearSelect(); _imageListView.Items[newindex].Selected = true; } currentFocusedItem.Focused = false; _imageListView.Items[newindex].Focused = true; EnsureVisible(newindex); #endregion //触发事件 _imageListView.OnSelectedItemChanged(); } } _imageListView.NeedPaint(); }
public void MouseDown(MouseEventArgs e) { /* * 如果按下的是鼠标右键 * 如果按在已选定的项上,只切换焦点,不改变选择 * 如果按在未选定项上,则切换为点的项为选中项 * 不考虑键盘按键 */ _mouseItemsAreaOffset = _itemsAreaOffset; List <ShengListViewItem> oldSelectedItems = _imageListView.GetSelectedItems(); ShengListViewHitInfo hitInfo = HitTest(e.Location); if (hitInfo.ItemHit) { ShengListViewItem item = _imageListView.Items[hitInfo.ItemIndex]; List <ShengListViewItem> allItems = _imageListView.Items.ToList(); ShengListViewItem currentFocusedItem = _imageListView.FocusedItem; if (_imageListView.LeftButton) { #region 如果不允许多选 if (_imageListView.AllowMultiSelection == false) { //如果点击的项就是当前选择的项 if (oldSelectedItems.Count > 0 && oldSelectedItems.Contains(item)) { //判断Control键是否按下,如果按下了Control键,取消当前项的选择状态 if (_imageListView.ControlKey) { item.Selected = false; } } else { //如果点击的项不是当前选择的项 //清除原选定项的选定状态 _imageListView.ClearSelect(); //设置新项为选定项 item.Selected = true; } } #endregion #region 如果允许多选 //在同时按下 Control 和 Shift 的情况下,优先考虑 Shift else { #region 如果按下 Shift //判断是否按下了 Shift ,如果按下 Shift,不考虑 Control 的状态 //也不用考虑是否点击的项是否是现有选定项之一 if (_imageListView.ShiftKey) { //如果当前存在具有输入焦点的项 if (currentFocusedItem != null && currentFocusedItem != item) { //连续选中从当前具有焦点的项至点击的项之间的所有项 //并将不在此范围内的项取消选中状态 int startIndex = Math.Min(currentFocusedItem.Index, hitInfo.ItemIndex); int endIndex = Math.Max(currentFocusedItem.Index, hitInfo.ItemIndex); foreach (var i in from c in oldSelectedItems where c.Index <startIndex || c.Index> endIndex select c) { i.Selected = false; } for (int i = startIndex; i <= endIndex; i++) { ShengListViewItem eachItem = allItems[i]; if (eachItem.Selected == false) { eachItem.Selected = true; } } } //如果当前不存在具有输入焦点的项 else { //清除原选定项的选定状态 _imageListView.ClearSelect(); item.Selected = true; } } #endregion #region 如果 Shift键没有处于按下状态 else { #region 如果点击的项 是 当前选择的项之一 if (oldSelectedItems.Count > 0 && oldSelectedItems.Contains(item)) { //判断是否按下了 Control,且没有按下 Shift if (_imageListView.ControlKey && _imageListView.ShiftKey == false) { item.Selected = false; } //判断是否什么键都没有按下 if (_imageListView.ControlKey == false && _imageListView.ShiftKey == false) { //清除原选定项的选定状态 _imageListView.ClearSelect(); item.Selected = true; } } #endregion #region 如果点击的项 不是 当前选择的项之一 else { //判断Control键是否按下,如果按下了Control键,则保持原有选择的情况把新项也设置为选中 //否则清除当前选择 if (_imageListView.ControlKey == false) { //清除原选定项的选定状态 _imageListView.ClearSelect(); } item.Selected = true; } #endregion } #endregion } #endregion } else { //如果点在未选中的项上 if (oldSelectedItems.Contains(item) == false) { _imageListView.ClearSelect(); //设置新项为选定项 item.Selected = true; } } #region 为项设置输入焦点 //设置新的输入焦点要放在后面处理,因为在使用Shift连续选择时,需要用到原具有焦点的项 if (currentFocusedItem == null || (currentFocusedItem != null && currentFocusedItem != item)) { if (currentFocusedItem != null) { currentFocusedItem.Focused = false; } item.Focused = true; } #endregion } else { _imageListView.ClearSelect(); } List <ShengListViewItem> newSelectedItems = _imageListView.GetSelectedItems(); if (oldSelectedItems.SequenceEqual(newSelectedItems) == false) { _imageListView.NeedPaint(); _imageListView.OnSelectedItemChanged(); } }
/// <summary> /// 获取项的呈现区域 /// </summary> /// <param name="item"></param> /// <returns></returns> public Rectangle GetItemBounds(ShengListViewItem item) { int index = _imageListView.Items.IndexOf(item); return(GetItemBounds(index)); }
public void RenderItem(Graphics graphics, ShengListViewItem item) { Debug.Assert(MouseSelecting == false, "MouseSelecting 为 " + MouseSelecting.ToString()); _renderer.RenderItem(graphics, item); }
public ShengListViewItemDoubleClickEventArgs(ShengListViewItem item) { Item = item; }