GetItemHeight() публичный Метод

public GetItemHeight ( int index ) : int
index int
Результат int
        /// <summary>
        /// Show a listbox with possible completions for the uncompleted string.
        /// When the user chooses one and presses enter (or clicks it with the mouse),
        /// return the chosen completion. Or, when the user presses escape, then 
        /// close the window and return null.
        /// </summary>        
        public string ShowTooltip(string uncompleted, IEnumerable<string> completions, IEnumerable<string> documentations,Point location)
        {
            _lstCompletions = new ListBox();
            _lstCompletions.ScrollAlwaysVisible = true;
            _lstCompletions.Items.AddRange(completions.ToArray());
            _lstCompletions.SelectionMode = SelectionMode.One;
            _lstCompletions.AutoSize = false;
            _lstCompletions.SelectedIndexChanged += new EventHandler(selectedIndexChanged);
            _lstCompletions.Click += new EventHandler(lstCompletionsClicked);

            int maxWidth = 0;
            for (int i = 0; i < _lstCompletions.Items.Count; i++)
            {
                if (_lstCompletions.GetItemRectangle(i).Width > maxWidth)
                    maxWidth = _lstCompletions.GetItemRectangle(i).Width;
            }
            _lstCompletions.Width = maxWidth;
            if (_lstCompletions.Items.Count > 0)
                _lstCompletions.Height = _lstCompletions.GetItemHeight(0) * 10;

            _documentations = documentations;
            _lblDocumentation = new TextBox();
            _lblDocumentation.WordWrap = true;
            _lblDocumentation.Width = _lstCompletions.Width;
            _lblDocumentation.BackColor = SystemColors.ControlLight;
            if (_documentations!=null && _documentations.Count() > 0)
                _lblDocumentation.Text = _documentations.ElementAt(0);
            _lblDocumentation.ScrollBars = ScrollBars.Vertical;
            _lblDocumentation.Multiline = true;
            _lblDocumentation.AutoSize = true;
            _lblDocumentation.Height = 100;
            _lblDocumentation.ReadOnly = true;

            _dialog = new CompletionToolTipWindow(_lstCompletions,_lblDocumentation);
            _dialog.KeyDown += new KeyEventHandler(dialog_KeyDown);
            _dialog.Location = location;
            _dialog.KeyPreview = true;
            _dialog.ShowDialog();

            if (_cancel || _lstCompletions.SelectedIndex < 0)
                return null;

            return (string)_lstCompletions.SelectedItem;
        }
Пример #2
0
        /// <summary>
        /// The item insert.
        /// </summary>
        /// <param name="lb">The lb.</param>
        /// <param name="itemToInsert">The item to insert.</param>
        /// <param name="position">The position.</param>
        /// <remarks></remarks>
        private void itemInsert(ListBox lb, object itemToInsert, Point position)
        {
            int totalHeight = 0;
            int itemNum = -1;
            do
            {
                totalHeight += lb.GetItemHeight(++itemNum);
            }
            while (position.Y > totalHeight && itemNum < lb.Items.Count - 1);
            itemNum += lbMapListing.TopIndex;
            if (itemNum >= lb.Items.Count)
            {
                itemNum = lb.Items.Count - 1;
            }

            if (lb.Items[itemNum] != itemToInsert)
            {
                int oldPos = lb.Items.IndexOf(itemToInsert);
                if (oldPos < itemNum)
                {
                    lb.Items.Insert(itemNum + 1, itemToInsert);
                    lb.Items.RemoveAt(oldPos);
                    currentLevels.Insert(itemNum + 1, currentLevels[oldPos]);
                    currentLevels.RemoveAt(oldPos);
                }
                else
                {
                    lb.Items.Insert(itemNum, itemToInsert);
                    lb.Items.RemoveAt(oldPos + 1);
                    currentLevels.Insert(itemNum, currentLevels[oldPos]);
                    currentLevels.RemoveAt(oldPos + 1);
                }

                lb.SelectedItem = itemToInsert;
            }
        }