简体   繁体   English

C#-悬停按钮可删除透明背景

[英]C# - Hovering a button removes transparent background

I'm developing an application which has several buttons with a transparent background. 我正在开发一个应用程序,该应用程序具有多个具有透明背景的按钮。 One of these is a custom exit button, rather than using the standard windows border. 其中之一是自定义退出按钮,而不是使用标准的Windows边框。 This exit button has two colors, the other which is shown using the MouseEnter event. 此退出按钮有两种颜色,另一种通过MouseEnter事件显示。 The exit button is a cross with a transparent background. 退出按钮是带有透明背景的十字形。

The transparent background works fine, until you hover the button. 直到您将按钮悬停为止,透明背景才能正常工作。 Then the backcolor somehow appears to change to Control and the transparency is lost. 然后,背景色似乎以某种方式变为Control,并且透明度丢失。 Once you move the cursor away from the button it's back to normal. 一旦将光标从按钮上移开,它就会恢复正常。 The weird thing here is that the exact same button with the exact same code works on several other windows except this one, which is the main form. 奇怪的是,具有完全相同代码的完全相同按钮可在除主窗口之外的其他几个窗口上工作。

I tried removing all Mouseevents and click events and only have a button with a transparent background. 我尝试删除所有Mouseevents和click事件,并且只有一个带有透明背景的按钮。 Now, even without any MouseEnter event and without any change of the button background image, the transparency is lost once you hover the button. 现在,即使没有任何MouseEnter事件,并且按钮背景图片没有任何更改,将鼠标悬停在按钮上时透明度也会丢失。 So basically this is a static button with no function at all which still reacts once you hover it by changing the BackColor, why? 因此,基本上这是一个完全没有功能的静态按钮,一旦您通过更改BackColor悬停它仍会做出反应,为什么?

I have a vague memory of experiencing this issue before but I just can't seem to figure out what I did to solve it. 我以前曾经遇到过这个问题,记忆犹新,但是我似乎无法弄清楚该如何解决。

Thanks in advance, Fredrik 在此先感谢Fredrik

I have now found the issue. 我现在发现了问题。 If anyone else is experiencing this issue, make sure to set your MouseDownBackColor and MouseOverBackColor to Transparent in the FlatAppearance section. 如果其他任何人都遇到此问题,请确保在FlatAppearance部分中将MouseDownBackColor和MouseOverBackColor设置为Transparent。 That did the trick. 做到了。

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

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