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


C# CheckedListBox.CreateGraphics方法代码示例

本文整理汇总了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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:UIHelper.cs

示例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;
        }
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:61,代码来源:FlagsUITypeEditor.cs


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