【问题标题】:Remove button border when entered输入时移除按钮边框
【发布时间】:2013-10-31 08:48:58
【问题描述】:

当我将鼠标悬停在 C# 表单上的按钮上时,我将它们突出显示为黄色,就像 Microsoft Office 产品一样,但我不希望它显示按钮边框。我见过有人提到 FlatStyle 或 FlatAppearance,但它似乎无法识别这些命令。我现在正在研究渲染,但我是 C# 新手,我确信一定有一种简单的方法可以做到这一点,如果可能的话,我不想花很多时间。

我必须强调,我一直在阅读有关 Windows 窗体编程的书籍,但没有找到任何答案,这并不是因为我很懒,而是我经常发现 SO 是一个非常好的来源,而且输入非常好。

试过这个:

this.TSVehicleButton.BorderStyle = None;

试过这个:

this.TSVehicleButton.System.Windows.Forms.BorderStyle = None;

我尝试了很多东西,但没有在我的问题中提及它,我是 C# 的新手,不想给人留下愚蠢的印象。当人们把他们尝试过但不正确的东西放在一起时,人们会变得有点讨厌。

【问题讨论】:

  • 你在用winforms吗?
  • 是的,我是 @Sharad 在 VS05 中开发

标签: c# button toolstrip


【解决方案1】:

上使用以下
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);
    }
}

我可以帮你。

【讨论】:

  • 干杯,我在这本书中注意到了类似的事情,我将研究这个,感觉奇怪的是解决方案应该像这样复杂,但我认为这是因为我的语言习惯了。
【解决方案2】:

只需使用this.FlatStyle = FlatStyle.Flat;

【讨论】:

    【解决方案3】:

    只需在属性窗口中设置以下Button 属性,例如在设计时:

    FlatStyle=Flat
    FlatAppearance.BorderSize=0
    

    或者运行以下代码,例如一个名为button1的按钮:

    button1.FlatStyle=True
    button1.FlatAppearance.BorderSize=0
    

    【讨论】:

      【解决方案4】:

      这对我来说非常有效,而且非常简单!

      button.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); // transparent
      button.FlatAppearance.BorderSize = 0;
      

      现在按钮没有边框了,即使你输入了光标。这在 Visual Studio 2015 上完美运行。

      【讨论】:

        【解决方案5】:

        有一种方法可以将边框从按钮及其属性中移开。 首先确保您已单击按钮,以便属性属于该按钮。 在属性窗格上找到平面外观并通过单击它前面的 + 号来展开它。 这将为您打开更多选项,其中一个选项是边框大小,设置为 1,将其更改为 0, 接下来,在下面的 3 行中,有一个名为 FlatStyle 的属性并将其设置为标准,需要将其更改为 Flat。 Flat 大功告成!

        希望对你有帮助

        【讨论】:

          猜你喜欢
          • 2016-10-20
          • 2019-04-25
          • 1970-01-01
          • 1970-01-01
          • 2023-03-30
          • 1970-01-01
          • 1970-01-01
          • 2013-11-22
          相关资源
          最近更新 更多