当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.GetItemHeight方法代码示例

本文整理汇总了C#中System.Windows.Forms.ListBox.GetItemHeight方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.GetItemHeight方法的具体用法?C# ListBox.GetItemHeight怎么用?C# ListBox.GetItemHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ListBox的用法示例。


在下文中一共展示了ListBox.GetItemHeight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowTooltip

        /// <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;
        }
开发者ID:JGalvezTT,项目名称:revitpythonshell,代码行数:50,代码来源:CompletionToolTip.cs

示例2: itemInsert

        /// <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;
            }
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:43,代码来源:MainMenuEdit.cs


注:本文中的System.Windows.Forms.ListBox.GetItemHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。