简体   繁体   English

删除选项卡C#Winforms上的按钮边框

[英]Remove button border on tab c# winforms

I have a button on my form that has flat style applied and uses a background image, I have removed all borders from the button, but when I tab onto the button from another control a black border appears around the button. 我的表单上有一个应用了平面样式并使用背景图像的按钮,我删除了该按钮的所有边框,但是当我从另一个控件切换到该按钮时,该按钮周围会出现黑色边框。

This can be seen in the image below. 可以在下图中看到。 On the left is the button with black border on the right is a different button but shows how the cancel button should look. 左侧是带有黑色边框的按钮,右侧是另一个按钮,但显示了取消按钮的外观。

纽扣

I do not get this border, if I set the BoderSize to 0 in the FlatAppearance section. 我没有得到这个边界,如果我设置BoderSize0FlatAppearance部分。


Further investigation shows that this border appears only when the button is the default button. 进一步的调查表明,只有当按钮是默认按钮时,才会出现该边框。 You can create your own button, which does never show this border like this 您可以创建自己的按钮,它永远不会像这样显示边框

public class NoNotifyButton: System.Windows.Forms.Button
{
    public override void NotifyDefault(bool value)
    {
    }
}

Note: NotifyDefault remains intentionally empty. 注意: NotifyDefault有意保留为空。

你必须要使用一个新的按钮类IButtonControl和变化NotifyDefault为false:

base.NotifyDefault(false);

您可以将按钮属性“ ForeColor”设置为透明

You don't have to create a derived class. 您不必创建派生类。 You can set the ForeColor to be the same as parent control BackColor. 您可以将ForeColor设置为与父控件BackColor相同。 As follows : 如下 :

btn1.ForeColor = btn1.Parent.BackColor;

I managed to get around this by setting the button TabStop property to False and then using this code on the button click event 我设法通过将按钮TabStop属性设置为False,然后在按钮单击事件上使用此代码来解决此问题

private void sendBackTab()
        {
            System.Windows.Forms.SendKeys.SendWait("+{TAB}");
        }

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

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