读书人

C# Winform 去掉按钮按上时周围黑线框

发布时间: 2012-07-15 20:11:37 作者: rapoo

C# Winform 去掉按钮按下时周围黑线框

C# Winform 去掉按钮按下时周围黑线框
2011年03月01日
  C# Winform界面编程时拖放的按钮很不美观,如果要贴一个透明的png图片,需要做一些属性设置,this代表此Button。
  this.BackColor = System.Drawing.Color.Transparent;
  //this.BackgroundImage = global::WindowsFormsApplication1.Properties.Resour ces.back;
  this.BackgroundImage = System.Drawing.Image.FromFile("../../image/spalish .jpg");
  this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
  this.FlatAppearance.BorderSize = 0;
  this.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent;
  this.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent;
  this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  这样设置后,按钮按下去时,还是去出现黑线框,这个黑线框通过属性设置时无法去掉的,需要自定义按钮,然后重绘。
  这个黑线框式聚焦框,有系统绘制。可以按如下方式自定义按钮后就可顺利去掉此黑线框。
  //自定义了一个Button。点击Button时不会出现黑色边框
  public class MyButton : Button
  {
  public MyButton()
  {
  }
  protected override bool ShowFocusCues
  {
  get
  {
  return false;
  }
  }
  }

读书人网 >C#

热点推荐