Ejemplo n.º 1
0
 /// <summary>
 /// Closes the visible menu (if any)
 /// </summary>
 public static bool ForceClose()
 {
     if (_popup != null)
     {
         try {
             _popup.Close();
             _popup.Dispose();
         } catch (Exception) {
             // ignored
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// displays the popup form
        /// </summary>
        private void DisplayPopup(string initialString)
        {
            if (_listItems != null && _listItems.Count > 0)
            {
                var displayFilterBox = !string.IsNullOrEmpty(initialString) || _listItems.Count > 15;

                // correct default selected
                foreach (var item in _listItems)
                {
                    item.IsSelectedByDefault = item.Index == SelectedIndex;
                }

                var spawnPt = PointToScreen(new Point());
                spawnPt.Offset(0, displayFilterBox ? 0 : Height);
                _listPopup = new YamuiMenu {
                    SpawnLocation            = spawnPt,
                    MenuList                 = _listItems.Cast <YamuiMenuItem>().ToList(),
                    DisplayFilterBox         = displayFilterBox,
                    Resizable                = false,
                    Movable                  = false,
                    FormMinSize              = new Size(Width, 0),
                    AutocompletionLineHeight = (displayFilterBox ? -1 : 1) * Height,
                    InitialFilterString      = initialString
                };

                // on popup clic
                _listPopup.ClicItemWrapper = item => {
                    if (item != null)
                    {
                        SelectedIndex = ((YamuiComboItem)item).Index;
                        if (SelectedIndexChangedByUser != null)
                        {
                            SelectedIndexChangedByUser(this);
                        }
                    }
                    _listPopup.Close();
                    _listPopup.Dispose();
                };

                // show
                var owner = FindForm();
                if (owner != null)
                {
                    _listPopup.Show(new WindowWrapper(owner.Handle));
                }
                else
                {
                    _listPopup.Show();
                }

                _listPopup.YamuiList.IndexChanged += list => {
                    var item = list.SelectedItem;
                    if (item != null)
                    {
                        SelectedIndex = ((YamuiComboItem)item).Index;
                        if (SelectedIndexChangedByUser != null)
                        {
                            SelectedIndexChangedByUser(this);
                        }
                    }
                };
            }
        }