简体   繁体   English

C#Winforms-平面按钮样式-透明边框

[英]C# Winforms - Flat Button Style - Transparent Border

I've recently created a new control - a flat button - so no border, transparent background, no mouse down color, etc. The problem is, once the app is compiled and running, a black border is around the transparent background. 我最近创建了一个新控件-扁平按钮-因此没有边框,透明背景,没有鼠标按下颜色等。问题是,一旦应用程序被编译并运行,透明背景周围就会出现黑色边框。 I am going to attach two images - the first is how it looks on the app while running and second is how it looks on the design screen (how i want it to look). 我要附加两个图像-第一个是它在运行时在应用程序上的外观,第二个是它在设计屏幕上的外观(我希望它的外观)。 I'd appreciate any help getting this border to go away. 非常感谢您能帮忙解决这个问题。 Thank you! 谢谢!

public FlatButton() : base()
{
    FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    FlatAppearance.BorderSize = 0;
    FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);
    BackColor = Color.FromArgb(0, 255, 255, 255);    
}

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    Pen pen = new Pen(FlatAppearance.BorderColor, 0);
    Rectangle rectangle = new Rectangle(0, 0, Size.Width - 2, Size.Height - 2);
    e.Graphics.DrawRectangle(pen, rectangle);   
}

在应用程式中

在设计师

Try setting TabStop = false; 尝试将TabStop设置为false; in the constructor of this FlatButton class. 在此FlatButton类的构造函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM