コード例 #1
0
        /// <summary>
        /// Gets the list view width large enough to handle the longest completion data
        /// text string.
        /// </summary>
        /// <param name="defaultWidth">The default width of the list view.</param>
        /// <param name="height">The height of the list view.  This is
        /// used to determine if the scrollbar is visible.</param>
        /// <returns>The list view width to accommodate the longest completion
        /// data text string; otherwise the default width.</returns>
        private int GetListViewWidth(int defaultWidth, int height)
        {
            float width = defaultWidth;

            using (Graphics graphics = codeCompletionListView.CreateGraphics())
            {
                for (int i = 0; i < completionData.Length; ++i)
                {
                    float itemWidth = graphics.MeasureString(completionData[i].Text, codeCompletionListView.Font).Width;

                    if (itemWidth > width)
                    {
                        width = itemWidth;
                    }
                }
            }

            float totalItemsHeight = codeCompletionListView.ItemHeight * completionData.Length;

            if (totalItemsHeight > height)
            {
                width += ScrollbarWidth;                 // Compensate for scroll bar.
            }

            return((int)width);
        }