本文整理汇总了C#中System.Windows.Forms.CheckedListBox.CreateGraphics方法的典型用法代码示例。如果您正苦于以下问题:C# CheckedListBox.CreateGraphics方法的具体用法?C# CheckedListBox.CreateGraphics怎么用?C# CheckedListBox.CreateGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.CheckedListBox
的用法示例。
在下文中一共展示了CheckedListBox.CreateGraphics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFieldsCheckedListBoxColumnWidth
internal static void UpdateFieldsCheckedListBoxColumnWidth(CheckedListBox checkedListBox)
{
int num = 0;
using (Graphics graphics = checkedListBox.CreateGraphics())
{
foreach (object obj2 in checkedListBox.Items)
{
string text = obj2.ToString();
num = Math.Max(num, (int) graphics.MeasureString(text, checkedListBox.Font).Width);
}
}
num += 50;
checkedListBox.ColumnWidth = num;
}
示例2: EditValue
/// <summary>
/// Edits the specified object's value using the editor style indicated by the
/// System.Drawing.Design.UITypeEditor.GetEditStyle() method</summary>
/// <param name="context">An System.ComponentModel.ITypeDescriptorContext that can be used to gain
/// additional context information</param>
/// <param name="provider">An System.IServiceProvider that this editor can use to obtain services</param>
/// <param name="value">The object to edit</param>
/// <returns>The new value of the object. If the value of the object has not changed, this should
/// return the same object it was passed.</returns>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
m_editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (m_editorService != null)
{
CheckedListBox checkedListBox = new CheckedListBox();
checkedListBox.CheckOnClick = true;
foreach (string displayName in m_displayNames)
checkedListBox.Items.Add(displayName);
// size control so all strings are completely visible
using (System.Drawing.Graphics g = checkedListBox.CreateGraphics())
{
float width = 0f;
foreach (string displayName in m_displayNames)
{
float w = g.MeasureString(displayName, checkedListBox.Font).Width;
width = Math.Max(width, w);
}
float height = m_displayNames.Length * checkedListBox.ItemHeight;
int scrollBarThickness = SystemInformation.VerticalScrollBarWidth;
if (height > checkedListBox.Height - 4) // vertical scrollbar?
width += SystemInformation.VerticalScrollBarWidth;
if (width > checkedListBox.Width)
checkedListBox.Width = (int)width + 31; // magic number from Windows.Forms dll
}
if (value is string)
FillCheckedListBoxFromString(value, checkedListBox);
else if (value is int)
FillCheckedListBoxFromInt(value, checkedListBox);
// otherwise, ignore value
m_editorService.DropDownControl(checkedListBox);
object newValue;
if (value is string)
newValue = ExtractStringFromCheckedListBox(checkedListBox);
else
newValue = ExtractIntFromCheckedListBox(checkedListBox);
// be careful to return the same object if the value didn't change
if (!newValue.Equals(value))
value = newValue;
}
return value;
}