本文整理汇总了C#中System.Windows.Forms.ButtonRenderer.DrawButton方法的典型用法代码示例。如果您正苦于以下问题:C# ButtonRenderer.DrawButton方法的具体用法?C# ButtonRenderer.DrawButton怎么用?C# ButtonRenderer.DrawButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ButtonRenderer
的用法示例。
在下文中一共展示了ButtonRenderer.DrawButton方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPaint
// Draw the large or small button, depending on the current state.
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Draw the smaller pressed button image
if (state == PushButtonState.Pressed)
{
// Set the background color to the parent if visual styles
// are disabled, because DrawParentBackground will only paint
// over the control background if visual styles are enabled.
this.BackColor = Application.RenderWithVisualStyles ?
Color.Azure : this.Parent.BackColor;
// If you comment out the call to DrawParentBackground,
// the background of the control will still be visible
// outside the pressed button, if visual styles are enabled.
ButtonRenderer.DrawParentBackground(e.Graphics,
ClientRectangle, this);
ButtonRenderer.DrawButton(e.Graphics, ClickRectangle,
this.Text, this.Font, true, state);
}
// Draw the bigger unpressed button image.
else
{
ButtonRenderer.DrawButton(e.Graphics, ClientRectangle,
this.Text, this.Font, false, state);
}
}
// Draw the smaller pressed button image.
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.Text = "Clicked!";
state = PushButtonState.Pressed;
Invalidate();
}
// Draw the button in the hot state.
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.Text = "Click here";
state = PushButtonState.Hot;
Invalidate();
}
// Draw the button in the unpressed state.
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.Text = "Click here";
state = PushButtonState.Normal;
Invalidate();
}