public FlatListItemList InItemList() { FlatListItem fli = InItem(); if (fli == null) { return(Items); } return(fli.SubItems); }
protected override void OnMouseDown(MouseEventArgs e) { if (DesignMode) { return; } int iItem = ItemAtPoint(e.Location); if (_CheckboxStyle) { if (iItem == -1) { return; } FlatListItem i = InItemList()[iItem]; i.Checked = !i.Checked; Invalidate(); return; } if (iItem == -1 && !_ClickDeselects) { return; } if (e.Button == MouseButtons.Left) { Select(iItem, _MultiSelect && (ModifierKeys & Keys.Control) != 0); } FlatListItem item = null; if (iItem != -1) { item = InItemList()[iItem]; item.CallOnSelected(this, e); } if (SelectedItemClicked != null) { SelectedItemClicked(this, new FlatListItemClickedEventArgs() { Item = item, MouseButton = e.Button, MouseLocation = e.Location }); } base.OnMouseDown(e); }
protected override void OnPaint(PaintEventArgs e) { if (Parent is FlatArrowContainer) { // we only have to draw the background manually here if we're in a FlatArrowContainer e.Graphics.Clear(BackColor); } FlatListItemList flil = Items; if (!DesignMode) { FlatListItem fliInItem = InItem(); if (fliInItem != null) { flil = fliInItem.SubItems; if (!InItemLabel.Visible) { InItemLabel.Visible = true; InItemLabel.BackColor = _BorderColor; InItemLabel.ForeColor = ForeColor; InItemLabel.Height = _ItemHeight; InItemLabel.Left = this.Left; InItemLabel.Top = this.Top; this.Top = InItemLabel.Top + InItemLabel.Height; this.Height -= InItemLabel.Height; } InItemLabel.Text = " < " + fliInItem.Text; } else { if (InItemLabel.Visible) { InItemLabel.Visible = false; this.Top = InItemLabel.Top; this.Height += InItemLabel.Height; } } } e.Graphics.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y); for (int i = 0; i < flil.Count; i++) { DrawItem(i, flil[i], e); } base.OnPaint(e); }
public FlatListItem InItem() { FlatListItem ret = null; for (int i = 0; i < InItemStack.Count; i++) { if (ret == null) { ret = Items[InItemStack[i]]; } else { ret = ret.SubItems[InItemStack[i]]; } } return(ret); }
private void DrawItem(int index, FlatListItem item, PaintEventArgs e) { Rectangle rect = RectangleForItem(index); if (!e.ClipRectangle.IntersectsWith(rect)) { return; } rect.X -= AutoScrollPosition.X; rect.Y -= AutoScrollPosition.Y; int itemImageSize = _ItemImageSize; int itemImagePadding = itemImageSize + _ItemImageSizeSpacing * 2; Color foreColor = ForeColor; if (item.ForeColor != Color.Empty) { foreColor = item.ForeColor; } Color foreColorSub = _ForeColorSub; if (item.ForeColorSub != Color.Empty) { foreColorSub = item.ForeColorSub; } Color backColor = item.BackColor; if (index == HoverIndex) { backColor = _HoverColor; } if ((!_CheckboxStyle && SelectedIndices.Contains(index)) || (_CheckboxStyle && item.Checked)) { backColor = _SelectionColor; foreColor = _SelectionTextColor; } if (backColor != Color.Empty) { using (SolidBrush brush = new SolidBrush(backColor)) { e.Graphics.FillRectangle(brush, rect); } } if (item.Image != null) { e.Graphics.DrawImage(item.Image, new Rectangle(_PaddingX + _ItemImageSizeSpacing + rect.X, rect.Y + rect.Height / 2 - itemImageSize / 2, itemImageSize, itemImageSize)); } Font font = Font; if (item.Font != null) { font = item.Font; } Font fontSub = _FontSub; if (item.FontSub != null) { fontSub = item.FontSub; } PointF ptOffsetText = new PointF(0, 0); SizeF sizeText = e.Graphics.MeasureString(item.Text, font); SizeF sizeSubText = e.Graphics.MeasureString(item.SubText, fontSub); int textOffset = 0; int subtextOffset = 0; if (!sizeSubText.IsEmpty) { subtextOffset = ItemSubTextSpacing / 2; textOffset = -subtextOffset; } if (item.ShowProgress) { ptOffsetText.Y -= 4; } SolidBrush brushForeColor = new SolidBrush(foreColor); SolidBrush brushForeColorSub = new SolidBrush(foreColorSub); e.Graphics.DrawString(item.Text, font, brushForeColor, new PointF( ptOffsetText.X + _PaddingX + rect.X + itemImagePadding, ptOffsetText.Y + rect.Y + rect.Height / 2 - sizeText.Height / 2 - sizeSubText.Height / 2 + textOffset )); if (!sizeSubText.IsEmpty) { e.Graphics.DrawString(item.SubText, fontSub, brushForeColorSub, new PointF( ptOffsetText.X + _PaddingX + rect.X + itemImagePadding, ptOffsetText.Y + rect.Y + rect.Height / 2 - sizeText.Height / 2 + sizeSubText.Height / 2 + subtextOffset )); } if (_SubItemIndicator && item.SubItems != null && item.SubItems.Count > 0) { e.Graphics.DrawString(">", font, brushForeColor, new PointF( rect.Width - 16, ptOffsetText.Y + rect.Y + rect.Height / 2 - sizeText.Height / 2 )); } if (item.ShowProgress) { int iOffsetRight = _PaddingX * 2; if (VerticalScroll.Visible) { iOffsetRight += 16; } Point ptProgress = new Point( (int)(ptOffsetText.X + _PaddingX + rect.X + itemImagePadding + 2), (int)(ptOffsetText.Y + rect.Y + rect.Height / 2 - sizeText.Height / 2 + sizeSubText.Height + 8) ); Size sizeProgress = new Size(rect.Width - ptProgress.X - iOffsetRight, 8); Size sizeProgressFill = new Size((int)(sizeProgress.Width * item.Progress), 8); using (SolidBrush brush = new SolidBrush(foreColorSub.Lerp(this.BackColor, 0.6))) { e.Graphics.FillRectangle(brush, new Rectangle(ptProgress, sizeProgress)); } e.Graphics.FillRectangle(brushForeColor, new Rectangle(ptProgress, sizeProgressFill)); } brushForeColor.Dispose(); brushForeColorSub.Dispose(); }