/// <summary> /// Refresh all the buttons to display the right items /// </summary> private void RefreshButtons() { if (_nbRowDisplayed > 0) { // for each displayed item of the list for (int i = 0; i < _nbRowDisplayed; i++) { if (TopIndex + i > _nbItems - 1) { _rows[i].Visible = false; } else { // associate with the item var itemBeingDisplayed = GetItem(TopIndex + i); _rows[i].Tag = itemBeingDisplayed; if (!_rows[i].Visible) { _rows[i].Visible = true; } _rows[i].Height = RowHeight.ClampMax(_listRectangle.Height - i * RowHeight); } // repaint _rows[i].Invalidate(); } } Update(); // force to redraw the control immediately }
/// <summary> /// This method just add the number of buttons required to display the list /// </summary> protected virtual void DrawButtons() { // we already display the right number of items? if ((_nbRowDisplayed - 1) * RowHeight <= _listRectangle.Height && _listRectangle.Height <= _nbRowDisplayed * RowHeight) { return; } // how many items should be displayed? _nbRowDisplayed = _nbItems.ClampMax(_listRectangle.Height / RowHeight + 1); // for each displayed item of the list for (int i = 0; i < _nbRowDisplayed; i++) { // need to add button? if (i >= _rows.Count) { _rows.Add(new YamuiListRow { Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top, Name = i.ToString(), TabStop = i == 0, OnRowPaint = OnRowPaint }); _rows[i].KeyDown += (sender, args) => { OnKeyDown(args); }; _rows[i].ButtonPressed += OnRowClick; _rows[i].DoubleClick += OnRowClick; _rows[i].MouseEnter += OnRowMouseEnter; _rows[i].MouseLeave += OnRowMouseLeave; _rows[i].Enter += OnRowEnter; _rows[i].Leave += OnRowLeave; _rows[i].MouseMove += OnRowMouseMove; } _rows[i].Location = new Point(_listRectangle.Left, _listRectangle.Top + i * RowHeight); _rows[i].Size = new Size(_listRectangle.Width - (HasScrolls ? ScrollWidth : 0), RowHeight.ClampMax(_listRectangle.Height - i * RowHeight)); _rows[i].IsSelected = i == SelectedRowIndex; // add it to the visible controls if (!Controls.Contains(_rows[i])) { Controls.Add(_rows[i]); } } for (int i = _nbRowDisplayed; i < _rows.Count; i++) { if (Controls.Contains(_rows[i])) { Controls.Remove(_rows[i]); } } }