在Form C#外部单击后如何删除按钮边框? [英] How to delete button border after clicking outside of Form C#?

查看:173
本文介绍了在Form C#外部单击后如何删除按钮边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个简单的按钮,但是当我在获胜表格之外单击时,我的按钮显示黑色边框.顺便说一句,我将BorderSize设置为"0",并且在单击表单内部时效果很好.

I made a simple button, but when i click outside of win form my button getting a black border. By the way i set BorderSize to "0" and it works great while i clicking inside of my form.

this.button.FlatAppearance.BorderSize = 0;

那是它的样子.

推荐答案

一个简单的解决方法是设置

One simple workaround is to set the FlatAppearance.BorderColor of the Button to its Parent.BackColor:

this.button1.FlatAppearance.BorderColor = this.button1.Parent.BackColor;

您可以将此属性设置为订阅

You could set this Property subscribing to the ParentChanged event (or overriding OnParentChanged, if it's a Custom Control) if the Control can be assigned to another parent at some point.

您还可以使用

You can also perform the same operation in batch, using the HandleCreated event and have all the Buttons (with FlatStyle = FlatStyle.Flat) subscribe to the event in the Form's constructor:

public Form1()
{
    InitializeComponent();
    foreach (Button button in this.Controls.OfType<Button>().Where(btn => btn.FlatStyle == FlatStyle.Flat))
    {
        button.HandleCreated += (s, e) => { 
            button.FlatAppearance.BorderColor = button.Parent.BackColor; 
        };
    }
}

这篇关于在Form C#外部单击后如何删除按钮边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆