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


C# RadioButton.CreateGraphics方法代码示例

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


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

示例1: CreateRadioPanel

 /// <summary>
 /// Returns a default radiopanel.
 /// This panel will try to fit into the second column,
 /// if not it will take a new line and spread over the whole width.
 /// </summary>
 /// <param name="position">Position of the Panel.</param>
 /// <param name="tag">Tag for the panel, containing data about the RadioButtons.</param>
 /// <returns></returns>
 private Panel CreateRadioPanel(Position position, SingleSelectionList tag)
 {
   Panel panel = new Panel();
   panel.AutoSize = false;
   panel.Tag = tag;
   panel.TabIndex = position.NextTabIndex;
   panel.Name = "radioPanel" + position.TabIndex.ToString();
   bool takeNewLine = false; // needed to know the columnwidth when calculating the expected height
   List<RadioButton> items = new List<RadioButton>(tag.Items.Count);
   for (int i = 0; i < tag.Items.Count; i++)
   {
     RadioButton btn = new RadioButton();
     btn.AutoSize = false;
     btn.TabIndex = position.NextTabIndex;
     btn.Name = "radioButton" + position.TabIndex.ToString();
     btn.Text = tag.Items[i].Evaluate();
     btn.CheckAlign = ContentAlignment.TopLeft;
     btn.Checked = (i == tag.Selected);
     btn.CheckedChanged += _singleSelectionListChange;
     btn.Tag = i;
     SetHelp(btn, tag.Help.Evaluate());
     items.Add(btn);
     // see if we should take a new line (add 30 for the radiobutton and to cover too small measurements)
     btn.Width = (int)(btn.CreateGraphics().MeasureString(btn.Text, btn.Font).Width + 30);
     if (btn.Width > position.WidthColumnTwo)
       takeNewLine = true;
   }
   // we can't calculate the height before, because we don't know the available width (depends on takeNewLine)
   // => second loop is needed
   Position nPos = (Position)position.Clone();
   nPos.LinePosition = 0;
   int width; // values depend on the new line, we can't use Position
   if (takeNewLine)
   {
     width = position.Width - position.Margin;
   }
   else
   {
     width = position.WidthColumnTwo;
   }
   foreach (RadioButton btn in items)
   {
     btn.Location = new Point(0, nPos.LinePosition);
     if (btn.Width > width)  // doesn't fit in the column, we'll have to calculate the height to avoid overlapping controls
     {
       btn.MaximumSize = new Size(width, (int)((double)btn.Width / width * btn.Height + position.LineHeight - btn.Height));
       btn.MinimumSize = btn.MaximumSize;
       btn.AutoSize = true;
       nPos.LinePosition += btn.MaximumSize.Height;
     }
     else
       nPos.LinePosition += nPos.LineHeight;
     panel.Controls.Add(btn);
   }
   panel.Size = new Size(width, nPos.LinePosition);
   // Locate and return the panel
   if (!takeNewLine)
     panel.Location = new Point(position.StartColumnTwo, position.LinePosition);
   else
   {
     position.LinePosition += position.ItemHeight;
     panel.Location = new Point(position.StartColumnOne + position.Margin, position.LinePosition);
   }
   return panel;
 }
开发者ID:HAF-Blade,项目名称:MediaPortal-2,代码行数:73,代码来源:FormDesigner.cs


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