Remove button border on tab c# winforms

不羁岁月 提交于 2019-12-18 08:33:45

问题


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.


回答1:


I do not get this border, if I set the BoderSize to 0 in the FlatAppearance section.


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.




回答2:


You have to make a new button class using IButtonControl and change NotifyDefault to false:

base.NotifyDefault(false);



回答3:


You can do it setting the button property "ForeColor" to transparent




回答4:


You don't have to create a derived class. You can set the ForeColor to be the same as parent control BackColor. As follows :

btn1.ForeColor = btn1.Parent.BackColor;



回答5:


I managed to get around this by setting the button TabStop property to False and then using this code on the button click event

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


来源:https://stackoverflow.com/questions/9966462/remove-button-border-on-tab-c-sharp-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!