public void SyncChildren() { _selectedIndex = _itemSelect.SelectedIndex; // If we do not have enough already if (Count < _imageIndexCount) { // Create and add the number extra needed int create = _imageIndexCount - Count; for (int i = 0; i < create; i++) { Add(new ViewDrawMenuImageSelectItem(_viewManager, _itemSelect, _triple, this, _needPaint)); } } else if (Count > _imageIndexCount) { // Destroy the extra ones no longer needed int remove = Count - _imageIndexCount; for (int i = 0; i < remove; i++) { RemoveAt(0); } } // Tell each item the image it should be displaying for (int i = 0; i < _imageIndexCount; i++) { int imageIndex = i + _imageIndexStart; ViewDrawMenuImageSelectItem item = (ViewDrawMenuImageSelectItem)this[i]; item.ImageList = _imageList; item.ImageIndex = imageIndex; item.Checked = (_selectedIndex == imageIndex); item.Enabled = _enabled; } }
/// <summary> /// Initialize a new instance of the ImageSelectController class. /// </summary> /// <param name="viewManager">Owning view manager instance.</param> /// <param name="target">Target for state changes.</param> /// <param name="layout">Reference to layout of the image items.</param> /// <param name="needPaint">Delegate for notifying paint requests.</param> public MenuImageSelectController(ViewContextMenuManager viewManager, ViewDrawMenuImageSelectItem target, ViewLayoutMenuItemSelect layout, NeedPaintHandler needPaint) { Debug.Assert(viewManager != null); Debug.Assert(target != null); Debug.Assert(layout != null); Debug.Assert(needPaint != null); _mousePoint = CommonHelper.NullPoint; _viewManager = viewManager; _target = target; _layout = layout; NeedPaint = needPaint; }