本文整理汇总了C#中System.Windows.Forms.RadioButtonRenderer类的典型用法代码示例。如果您正苦于以下问题:C# RadioButtonRenderer类的具体用法?C# RadioButtonRenderer怎么用?C# RadioButtonRenderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RadioButtonRenderer类属于System.Windows.Forms命名空间,在下文中一共展示了RadioButtonRenderer类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Button
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace RadioButtonRendererSample
{
class Form1 : Form
{
Button button1 = new Button();
public Form1()
: base()
{
CustomRadioButton RadioButton1 = new CustomRadioButton();
button1.Location = new System.Drawing.Point(175, 231);
button1.Size = new System.Drawing.Size(105, 23);
button1.Text = "Toggle Style";
button1.Click += new System.EventHandler(this.button1_Click);
Controls.Add(RadioButton1);
Controls.Add(button1);
if (Application.RenderWithVisualStyles)
this.Text = "Visual Styles Enabled";
else
this.Text = "Visual Styles Disabled";
}
[STAThread]
static void Main()
{
// If you do not call EnableVisualStyles below, then
// RadioButtonRenderer.DrawRadioButton automatically detects
// this and draws the radio button without visual styles.
Application.EnableVisualStyles();
Application.Run(new Form1());
}
private void button1_Click(object sender, EventArgs e)
{
Application.VisualStyleState =
Application.VisualStyleState ^
VisualStyleState.ClientAndNonClientAreasEnabled;
GroupBoxRenderer.RenderMatchingApplicationState = true;
if (Application.RenderWithVisualStyles)
this.Text = "Visual Styles Enabled";
else
this.Text = "Visual Styles Disabled";
}
}
public class CustomRadioButton : Control
{
private Rectangle textRectangleValue = new Rectangle();
private bool clicked = false;
private RadioButtonState state = RadioButtonState.UncheckedNormal;
public CustomRadioButton()
: base()
{
this.Location = new Point(50, 50);
this.Size = new Size(100, 20);
this.Text = "Click here";
this.Font = SystemFonts.IconTitleFont;
}
// Define the text bounds so that the text rectangle
// does not include the radio button.
public Rectangle TextRectangle
{
get
{
using (Graphics g = this.CreateGraphics())
{
textRectangleValue.X = ClientRectangle.X +
RadioButtonRenderer.GetGlyphSize(g,
RadioButtonState.UncheckedNormal).Width;
textRectangleValue.Y = ClientRectangle.Y;
textRectangleValue.Width = ClientRectangle.Width -
RadioButtonRenderer.GetGlyphSize(g,
RadioButtonState.UncheckedNormal).Width;
textRectangleValue.Height = ClientRectangle.Height;
}
return textRectangleValue;
}
}
// Draw the radio button in the current state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
RadioButtonRenderer.DrawRadioButton(e.Graphics,
ClientRectangle.Location, TextRectangle, this.Text,
this.Font, clicked, state);
}
// Draw the radio button in the checked or unchecked state.
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (!clicked)
{
clicked = true;
this.Text = "Clicked!";
state = RadioButtonState.CheckedPressed;
Invalidate();
}
else
{
clicked = false;
this.Text = "Click here";
state = RadioButtonState.UncheckedNormal;
Invalidate();
}
}
// Draw the radio button in the hot state.
protected override void OnMouseHover(EventArgs e)
{
base.OnMouseHover(e);
state = clicked ? RadioButtonState.CheckedHot :
RadioButtonState.UncheckedHot;
Invalidate();
}
// Draw the radio button in the hot state.
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
this.OnMouseHover(e);
}
// Draw the radio button in the unpressed state.
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
state = clicked ? RadioButtonState.CheckedNormal :
RadioButtonState.UncheckedNormal;
Invalidate();
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:147,代码来源:RadioButtonRenderer
注:本文中的System.Windows.Forms.RadioButtonRenderer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论