当我将鼠标悬停在我的 C# 窗体上的按钮上时,我让它们以黄色突出显示,就像 Microsoft Office 产品一样,但我不希望它显示按钮边框。我见过有人提到 FlatStyle 或 FlatAppearance,但它似乎无法识别这些命令。我现在正在研究渲染,但我是 C# 的新手,我确信一定有一种简单的方法可以做到这一点,如果可能的话,我不想在这上面花很多时间。
我必须强调,我一直在通读有关 Windows 窗体编程的书籍,但没有找到任何答案,这并不是我懒惰,而是我经常发现 SO 是一个非常好的来源,具有非常好的输入。
试过这个:
this.TSVehicleButton.BorderStyle = None;
试过这个:
this.TSVehicleButton.System.Windows.Forms.BorderStyle = None;
我尝试了很多东西,但没有在我的问题中提及它,我是 C# 的新手,不想给人留下愚蠢的印象。当人们提出他们尝试过但不正确的东西时,人们会变得有点讨厌。
最佳答案
使用以下
public class CustomButton : Button
{
public CustomButton()
: base()
{
// Prevent the button from drawing its own border
FlatAppearance.BorderSize = 0;
FlatStyle = System.Windows.Forms.FlatStyle.Flat;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Draw Border using color specified in Flat Appearance
Pen pen = new Pen(FlatAppearance.BorderColor, 1);
Rectangle rectangle = new Rectangle(0, 0, Size.Width - 1, Size.Height - 1);
e.Graphics.DrawRectangle(pen, rectangle);
}
}
我可以帮你。
关于c# - 输入时移除按钮边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19701945/