窗休上有个按钮,我想让他由始于终都不显示虚边框,
在网上找到一段代码
class myButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
// 获得焦点的时候什么都不做
return false;
}
}
}当前窗体为活动状态时,按钮是不会显示虚边框,
但是再打开其他程序,按钮又显示虚边框,
怎么样当窗体为非活动状态时按钮也不显示虚边框???
在网上找到一段代码
class myButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get
{
// 获得焦点的时候什么都不做
return false;
}
}
}当前窗体为活动状态时,按钮是不会显示虚边框,
但是再打开其他程序,按钮又显示虚边框,
怎么样当窗体为非活动状态时按钮也不显示虚边框???
解决方案 »
- wpf如何实现类似QQ截图功能
- C#中能不能实现在dategridview中直接修改数据后更新到库,如果能怎么写啊
- 脚本错误
- 从dataset输出到xml,0.40总会输出成0.406787,郁闷求解!
- 问个问题, 大家不要笑我啊
- 数据库新增后datagridview同步更新并有提示
- 讨论有关面向对象中继承的问题
- VC局域网访问ACCESS数据库
- World Wide Web Publishing Service 总是手工 Start 后过不到1分钟它又自动 Stop
- 关于自动提交数据的问题
- 求助,撒分!!项目从win2003+iis6 移动到win2008+iis7 后项目就出错
- 请教ProviderHelper.InstantiateProviders方法
在样式里,设置
border:0;
{
Graphics g = e.Graphics;
RectangleF ref1 = button2.DisplayRectangle;
g.FillRectangle(new SolidBrush(Color.BlanchedAlmond),ref1);
g.DrawString("button3", new Font("宋体", 10), new SolidBrush(Color.Black), ref1.Left+ref1.Width/5,ref1.Top+ref1.Height/5,StringFormat.GenericTypographic);
}
类似这样 其他的楼主可看着自己调整吧~
{
重写 OnPaint
}
using System;
using System.Windows.Forms;
using System.Drawing;public class CustomButtom : ButtonBase, IButtonControl
{
private DialogResult _DialogResult; public CustomButtom()
{
} #region 基类和接口的实现 public DialogResult DialogResult
{
get
{
return this._DialogResult;
} set
{
if (Enum.IsDefined(typeof(DialogResult), value))
{
this._DialogResult = value;
}
}
}
public void NotifyDefault(bool value)
{
if (this.IsDefault != value)
{
this.IsDefault = value;
}
}
public void PerformClick()
{
if (this.CanSelect)
{
this.OnClick(new EventArgs());
}
} #endregion string msState = ""; protected override void OnMouseEnter(EventArgs eventargs)
{
base.OnMouseEnter(eventargs);
this.msState = "enter";
} protected override void OnMouseLeave(EventArgs eventargs)
{
base.OnMouseLeave(eventargs);
this.msState = "leave";
} protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
this.msState = "down";
} protected override void OnMouseUp(MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
this.msState = "up";
this.Refresh();
} protected override void OnPaint(PaintEventArgs e)
{
// base.OnPaint(e); Graphics g = e.Graphics; Color bg = this.BackColor;
Color fg = this.ForeColor; switch (this.msState)
{
case "enter":
bg = Color.LightSkyBlue;
break;
case "down":
bg = Color.SteelBlue;
fg = Color.White;
break;
case "up": Console.WriteLine(
this.RectangleToScreen(
this.ClientRectangle).Contains(
Cursor.Position.X, Cursor.Position.Y)); if (this.RectangleToScreen(
this.ClientRectangle).Contains(
Cursor.Position.X, Cursor.Position.Y))
{
bg = Color.LightSkyBlue;
}
break;
} g.Clear(bg); // 背景 // 绘制边框
g.DrawRectangle(Pens.SteelBlue,
0, 0, this.Width - 1, this.Height - 1); // 绘制默认按钮边框
if (this.IsDefault)
{
g.DrawRectangle(Pens.LightSalmon,
1, 1, this.Width - 3, this.Height - 3);
} // 绘制焦点边框
if (this.Focused)
{
ControlPaint.DrawFocusRectangle(g,
new Rectangle(4, 4, this.Width - 7, this.Height - 7));
} using (Brush b = new SolidBrush(fg))
{
// 计算 Text 的 SizeF
SizeF sf = g.MeasureString(this.Text, this.Font);
float x = (g.ClipBounds.Width - sf.Width) / 2.0f;
float y = (g.ClipBounds.Height - sf.Height) / 2.0f; // 绘制文本
g.DrawString(this.Text, this.Font, b, x, y);
}
}
}
1 程序在VISTA/WIN7上运行不会出现焦点框
2 不使用自带Button控件而使用Label等无焦点框控件代替.