有没有办法禁用或更好地绘制自己的焦点矩形进行常规按钮控制!(那条虚线看起来如此Windowss 95ish)
我注意到控件属性(FOR BUTTONS)没有ownerdrawfixed设置(我不知道这是否是用于解决方案的路径,尽管我已经看到它用于自定义其他控件).
Han*_*ant 13
做到这一点比听起来更棘手.毫无疑问,自定义按钮绘制不可覆盖的原因之一.这按预期工作:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
class MyButton : Button {
private VisualStyleRenderer renderer;
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
if (this.Focused && Application.RenderWithVisualStyles && this.FlatStyle == FlatStyle.Standard) {
if (renderer == null) {
VisualStyleElement elem = VisualStyleElement.Button.PushButton.Normal;
renderer = new VisualStyleRenderer(elem.ClassName, elem.Part, (int)PushButtonState.Normal);
}
Rectangle rc = renderer.GetBackgroundContentRectangle(e.Graphics, new Rectangle(0, 0, this.Width, this.Height));
rc.Height--;
rc.Width--;
using (Pen p = new Pen(Brushes.DarkGray)) {
e.Graphics.DrawRectangle(p, rc);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ada*_*dam 11
一起禁用焦点矩形的快速简便方法是将控件子类化并包含以下代码:
public class CustomButton : Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)