Beispiel #1
0
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            if (e.X >= Width - SelectionSize && e.Y >= Height - SelectionSize)
            {
                if (dropdown == false)
                {
                    int fittableitems = this.DropDownHeight / this.ItemHeight;
                    if (fittableitems == 0)
                    {
                        fittableitems = 5;
                    }

                    if (fittableitems > this.Items.Count())                             // no point doing more than we have..
                    {
                        fittableitems = this.Items.Count();
                    }

                    ddc.Size = new Size(this.DropDownWidth > 9 ? this.DropDownWidth : this.Width, fittableitems * this.ItemHeight + 4);
                    ddc.Show(FindForm());
                }
                else
                {
                    ddc.Hide();
                }

                dropdown = !dropdown;
            }
        }
        private void Activate()
        {
            if (Items.Count == 0 || !Enabled)
            {
                return;
            }

            _customdropdown = new DropDownCustom(this.Name);

            int fittableitems = this.DropDownHeight / this.ItemHeight;

            if (fittableitems == 0)
            {
                fittableitems = 5;
            }

            if (fittableitems > this.Items.Count())                             // no point doing more than we have..
            {
                fittableitems = this.Items.Count();
            }

            _customdropdown.Size = new Size(this.DropDownWidth > 9 ? this.DropDownWidth : this.Width, fittableitems * this.ItemHeight + 4);

            _customdropdown.SelectionBackColor       = this.DropDownBackgroundColor;
            _customdropdown.MouseOverBackgroundColor = this.MouseOverBackgroundColor;
            _customdropdown.ForeColor            = this.ForeColor;
            _customdropdown.BackColor            = this.BorderColor;
            _customdropdown.BorderColor          = this.BorderColor;
            _customdropdown.Items                = this.Items.ToList();
            _customdropdown.ItemHeight           = this.ItemHeight;
            _customdropdown.SelectedIndex        = this.SelectedIndex;
            _customdropdown.FlatStyle            = this.FlatStyle;
            _customdropdown.Font                 = this.Font;
            _customdropdown.ScrollBarColor       = this.ScrollBarColor;
            _customdropdown.ScrollBarButtonColor = this.ScrollBarButtonColor;

            _customdropdown.DropDown             += _customdropdown_DropDown;
            _customdropdown.SelectedIndexChanged += _customdropdown_SelectedIndexChanged;
            _customdropdown.OtherKeyPressed      += _customdropdown_OtherKeyPressed;
            _customdropdown.Deactivate           += _customdropdown_Deactivate;

            Control parent = this.Parent;

            while (parent != null && !(parent is Form))
            {
                parent = parent.Parent;
            }

            _customdropdown.Show(parent);

            // enforce size.. some reason SHow is scaling it probably due to autosizing.. can't turn off. force back
            _customdropdown.Size = new Size(this.DropDownWidth > 9 ? this.DropDownWidth : this.Width, fittableitems * this.ItemHeight + 4);
        }
Beispiel #3
0
        private void drawnPanelListSelection_Click(object sender, EventArgs e)
        {
            dropdown = new DropDownCustom("", true);

            dropdown.SelectionBackColor       = this.DropDownBackgroundColor;
            dropdown.ForeColor                = this.ForeColor;
            dropdown.BackColor                = this.DropDownBorderColor;
            dropdown.BorderColor              = this.DropDownBorderColor;
            dropdown.ScrollBarColor           = this.DropDownScrollBarColor;
            dropdown.ScrollBarButtonColor     = this.DropDownScrollBarButtonColor;
            dropdown.MouseOverBackgroundColor = this.DropDownMouseOverBackgroundColor;
            dropdown.ItemSeperatorColor       = this.DropDownItemSeperatorColor;

            dropdown.ItemHeight     = ImageList[0].Size.Height + 2;
            dropdown.Items          = TextList.ToList();
            dropdown.ItemSeperators = ListSelectionItemSeparators;
            dropdown.ImageItems     = ImageList.ToList();
            dropdown.FlatStyle      = FlatStyle.Popup;
            dropdown.Activated     += (s, ea) =>
            {
                Point location = drawnPanelListSelection.PointToScreen(new Point(0, 0));
                dropdown.Location = dropdown.PositionWithinScreen(location.X + drawnPanelListSelection.Width, location.Y);
                this.Invalidate(true);
            };
            dropdown.SelectedIndexChanged += (s, ea) =>
            {
                ChangePanel(dropdown.SelectedIndex);
            };

            dropdown.Deactivate += (s, ea) =>               // will also be called on selected index because we have auto close on (in constructor)
            {
                keepstripopen = false;
                MouseLeavePanelObjects(sender, e);      // same as a mouse leave on one of the controls
            };

            dropdown.Size = new Size(DropDownWidth, DropDownHeight);
            dropdown.Show(this.FindForm());
            keepstripopen = true;
        }
Beispiel #4
0
        private void AutoCompleteFinished()
        {
            //System.Diagnostics.Debug.WriteLine("{0} Show results {1}", Environment.TickCount % 10000, autocompletestrings.Count);
            inautocomplete = false;

            int count = autocompletestrings.Count;

            if (count > 0)
            {
                if (_cbdropdown != null && (autocompletelastcount < count || autocompletelastcount > count + 5))
                {
                    _cbdropdown.Close();
                    _cbdropdown = null;
                }

                if (_cbdropdown == null)
                {
                    _cbdropdown = new DropDownCustom("", false);

                    int fittableitems = this.DropDownHeight / this.DropDownItemHeight;

                    if (fittableitems == 0)
                    {
                        fittableitems = 5;
                    }

                    if (fittableitems > autocompletestrings.Count())                             // no point doing more than we have..
                    {
                        fittableitems = autocompletestrings.Count();
                    }

                    _cbdropdown.Size = new Size(this.DropDownWidth > 0 ? this.DropDownWidth : this.Width, fittableitems * this.DropDownItemHeight + 4);

                    _cbdropdown.SelectionBackColor = this.DropDownBackgroundColor;
                    _cbdropdown.ForeColor          = this.ForeColor;
                    _cbdropdown.BackColor          = this.DropDownBorderColor;
                    _cbdropdown.BorderColor        = this.DropDownBorderColor;
                    _cbdropdown.Items                    = autocompletestrings;
                    _cbdropdown.ItemHeight               = this.DropDownItemHeight;
                    _cbdropdown.SelectedIndex            = 0;
                    _cbdropdown.FlatStyle                = this.FlatStyle;
                    _cbdropdown.Font                     = this.Font;
                    _cbdropdown.ScrollBarColor           = this.DropDownScrollBarColor;
                    _cbdropdown.ScrollBarButtonColor     = this.DropDownScrollBarButtonColor;
                    _cbdropdown.MouseOverBackgroundColor = this.DropDownMouseOverBackgroundColor;
                    _cbdropdown.Activated               += _cbdropdown_DropDown;
                    _cbdropdown.SelectedIndexChanged    += _cbdropdown_SelectedIndexChanged;

                    _cbdropdown.Show(FindForm());
                    Focus();                // Major change.. we now keep the focus at all times
                }
                else
                {
                    _cbdropdown.Items.Clear();
                    _cbdropdown.Items = autocompletestrings;
                    _cbdropdown.Refresh();
                }

                autocompletelastcount = count;
            }
            else
            {
                if (_cbdropdown != null)
                {
                    //System.Diagnostics.Debug.WriteLine("{0} Close prev", Environment.TickCount % 10000);
                    _cbdropdown.Close();
                    _cbdropdown = null;
                }
            }
        }