c# - 输入时移除按钮边框

标签 c# button toolstrip

当我将鼠标悬停在我的 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/

相关文章:

c# - .NET 多线程。即时更新 UI

c# - ML.Net 数据加载器(内存)

html - CSS3 - 圆形按钮 - 圆形边(水平和垂直)

c# - <script runat ="server"> 与代码隐藏文件

html - 在 Bootstrap 3 中将文本显示在与 block 级按钮相同的行上

ios - Xcode运行按钮消失

c# - ToolStrip StatusLabel DoubleClick 事件不会引发

c# - 将 UltraCombo 添加到已格式化的 ToolStrip

c# - WinForms 工具提示项目大小适合