コード例 #1
0
        /// <summary>
        /// Initialize a new instance of the GalleryItemController class.
        /// </summary>
        /// <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 GalleryItemController(ViewDrawRibbonGalleryItem target,
                                     ViewLayoutRibbonGalleryItems layout,
                                     NeedPaintHandler needPaint)
        {
            Debug.Assert(target != null);
            Debug.Assert(layout != null);

            _mousePoint = CommonHelper.NullPoint;
            _target     = target;
            _layout     = layout;
            NeedPaint   = needPaint;
        }
コード例 #2
0
        public void SyncChildren()
        {
            int       required      = 0;
            int       selectedIndex = _gallery.SelectedIndex;
            ImageList imageList     = _gallery.ImageList;

            // Find out how many children we need
            if (imageList != null)
            {
                required = _gallery.ImageList.Images.Count;
            }

            // If we do not have enough already
            if (Count < required)
            {
                // Create and add the number extra needed
                int create = required - Count;
                for (int i = 0; i < create; i++)
                {
                    Add(new ViewDrawRibbonGalleryItem(_gallery, _triple, this, _needPaint));
                }
            }
            else if (Count > required)
            {
                // Destroy the extra ones no longer needed
                int remove = Count - required;
                for (int i = 0; i < remove; i++)
                {
                    RemoveAt(0);
                }
            }

            // Tell each item the image it should be displaying
            for (int i = 0; i < required; i++)
            {
                ViewDrawRibbonGalleryItem item = (ViewDrawRibbonGalleryItem)this[i];
                item.ImageList  = imageList;
                item.ImageIndex = i;
                item.Checked    = (selectedIndex == i);
            }
        }