简体   繁体   English

按钮颜色完全透明

[英]Button color totally transparent

So I have image in button but my problem is default color of button. 所以我在按钮中有图像,但是我的问题是按钮的默认颜色。 I changed back color of button to color of my panel but I still have border around it, is there a way to remove it so entire button color would be transparent and only image would be visible ? 我将按钮的背景色更改为面板的颜色,但是它周围仍然有边框,是否有办法将其删除,因此整个按钮的颜色将是透明的,只有图像可见?

button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderSize = 0;
button1.FlatAppearance.BorderColor = //Set your Background color here

By default, controls do not support transparent backcolors. 默认情况下,控件不支持透明的背景色。 However, you can allow your control to have a background color that is opaque, transparent, or partially transparent by using the Control.SetStyle Method in the constructor. 但是,通过使用构造函数中的Control.SetStyle方法,可以允许控件具有不透明,透明或部分透明的背景颜色。 The SetStyle method of the Control class allows you to set particular style preferences for your controls, and can be used to enable or disable support for transparent backcolors. Control类的SetStyle方法允许您为控件设置特定的样式首选项,并可用于启用或禁用对透明背景色的支持。

To give your control a transparent backcolor 为您的控件提供透明的背景色

  • In the Code Editor for your control, locate the constructor. 在控件的代码编辑器中,找到构造函数。
  • Call the SetStyle method of your form in the constructor. 在构造函数中调用表单的SetStyle方法。

    SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.SupportsTransparentBackColor,true);

This will enable your control to support a transparent backcolor. 这将使您的控件支持透明的背景色。

  • Beneath the line of code you added in step 1, add the following line. 在您在步骤1中添加的代码行之下,添加以下行。 This will set your control's BackColor to Transparent. 这会将控件的BackColor设置为Transparent。

    this.BackColor = Color.Transparent; this.BackColor = Color.Transparent;

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

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