/// <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> int GetListViewWidth(int defaultWidth, int height) { Graphics graphics = codeCompletionListView.CreateGraphics(); float width = defaultWidth; for (int i = 0; i < completionData.Length; ++i) { float itemWidth = graphics.MeasureString(completionData[i].Text.ToString(), codeCompletionListView.Font).Width; if (itemWidth > width) { width = itemWidth; } } graphics.Dispose(); float totalItemsHeight = 0; try { totalItemsHeight = codeCompletionListView.ItemHeight * completionData.Length; } catch (System.Exception) { totalItemsHeight = completionData.Length; } if (totalItemsHeight > height) { width += ScrollbarWidth; // Compensate for scroll bar. } return((int)width); }
/// <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> int GetListViewWidth(int defaultWidth, int height) { float width = defaultWidth; using (Graphics graphics = codeCompletionListView.CreateGraphics()) { for (int i = 0; i < completionData.Length; ++i) { var itemWidth = graphics.MeasureString(completionData[i].Text.ToString(), 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); }