Example #1
0
 public PanelSelectionList()
 {
     InitializeComponent();
     ddc = new DropDownCustom("PSDD", false);
     ddc.SelectedIndexChanged += Ddc_SelectedIndexChanged;
     ddc.Activated            += Ddc_DropDown;
     ddc.Deactivate           += Ddc_Deactivate;
 }
Example #2
0
 private void AutoCompleteTextBox_Click(object sender, EventArgs e)
 {
     if (_cbdropdown != null)
     {
         _cbdropdown.Close();
         _cbdropdown = null;
     }
 }
        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);
        }
Example #4
0
 // Sometimes, the user is quicker than the timer, and has commited to a selection before the results even come back.
 public void AbortAutoComplete()
 {
     if (waitforautotimer.Enabled)
     {
         waitforautotimer.Stop();
     }
     else if (_cbdropdown != null)
     {
         _cbdropdown.Close();
         _cbdropdown = null;
         Invalidate(true);
     }
 }
Example #5
0
        private void _cbdropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedindex = _cbdropdown.SelectedIndex;

            if (selectedindex >= 0 && selectedindex < _cbdropdown.Items.Count)
            {
                this.Text = _cbdropdown.Items[selectedindex];
                this.Select(this.Text.Length, this.Text.Length);
                _cbdropdown.Close();
                _cbdropdown = null;
                this.Invalidate(true);
                Focus();
            }
        }
Example #6
0
        // keys when WE have to focus, which we do all the time now, some need passing onto the control.

        private void AutoCompleteTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("{0} Keypress {1}", Environment.TickCount % 10000 , e.KeyCode);

            if (_cbdropdown != null)        // pass certain keys to the shown drop down
            {
                if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up || e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
                {
                    _cbdropdown.KeyDownAction(e);
                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.Escape)
                {
                    _cbdropdown.Close();
                    _cbdropdown = null;
                }
            }
        }
Example #7
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;
        }
Example #8
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;
                }
            }
        }