コード例 #1
0
ファイル: YamuiFilterBox.cs プロジェクト: zhitian/3P
        /// <summary>
        /// Call this method to initialize the usercontrol
        /// </summary>
        public void Initialize(YamuiFilteredTypeList list)
        {
            AssociatedList = list;
            DrawControl();

            // link events of the textbox to the list
            _filterBox.TextChanged += AssociatedList.OnTextChangedEvent;
            _filterBox.KeyDown     += FilterBoxOnKeyDown;
        }
コード例 #2
0
        public void Build(Point location, List <int> typeList, Action <object, EventArgs> clickHandler, YamuiFilteredTypeList parentList)
        {
            _parentFilteredList = parentList;

            var buttonSize = new Size(YamuiFilteredTypeList.TypeButtonWidth, parentList.BottomHeight);

            // for each distinct type of items, create the buttons
            int xPos           = -buttonSize.Width;
            int yPos           = 0;
            int nBut           = 0;
            int maxNbButPerRow = (int)Math.Ceiling(Math.Sqrt(typeList.Count));

            foreach (var type in typeList)
            {
                xPos += buttonSize.Width;
                if (nBut >= maxNbButPerRow)
                {
                    yPos += buttonSize.Height;
                    xPos  = 0;
                    nBut  = 0;
                }

                var button = new SelectorButton {
                    Size                 = buttonSize,
                    TabStop              = false,
                    Anchor               = AnchorStyles.Left | AnchorStyles.Top,
                    AcceptsAnyClick      = true,
                    HideFocusedIndicator = true,
                    Activated            = true,
                    BackGrndImage        = parentList.TypeImages.ContainsKey(type) ? parentList.TypeImages[type] : null,
                    Type                 = type,
                    Location             = new Point(xPos, yPos)
                };
                button.ButtonPressed += (sender, args) => {
                    clickHandler(sender, args);
                    foreach (SelectorButton control in _panel.Controls)
                    {
                        control.Activated = _parentFilteredList.IsTypeActivated(control.Type);
                    }
                };
                button.LostFocus += (sender, args) => CloseIfMouseOut();
                button.Activated  = _parentFilteredList.IsTypeActivated(type);
                _tooltip.SetToolTip(button, (parentList.TypeText.ContainsKey(type) && parentList.TypeText[type] != null ? parentList.TypeText[type] + "<br>" : "") + YamuiFilteredTypeList.TypeButtonTooltipText);

                if (!_panel.Controls.Contains(button))
                {
                    _panel.Controls.Add(button);
                }

                nBut++;
            }

            // Size the form
            Size        = new Size(maxNbButPerRow * buttonSize.Width + BorderWidth * 2, (int)Math.Ceiling((double)typeList.Count / maxNbButPerRow) * buttonSize.Height + BorderWidth * 2);
            MinimumSize = Size;
            MaximumSize = Size;

            // menu position
            var screen = Screen.FromPoint(location);

            if (location.X - MousePaddingInsideForm > screen.WorkingArea.X + screen.WorkingArea.Width / 2)
            {
                location.X = location.X - Width + MousePaddingInsideForm;
            }
            else
            {
                location.X -= MousePaddingInsideForm;
            }
            if (location.Y - MousePaddingInsideForm > screen.WorkingArea.Y + screen.WorkingArea.Height / 2)
            {
                location.Y = location.Y - Height + MousePaddingInsideForm;
            }
            else
            {
                location.Y -= MousePaddingInsideForm;
            }

            Location = location;
        }