C# ToolStrip is transparent but border is still visible?

拈花ヽ惹草 提交于 2019-12-04 03:54:21

问题


I have a ToolStrip in a C# application that I set the background color to Transparent. This reveals the underlying form's color but unfortunately the ToolStrip border is still visible.

I've implemented a Custom Renderer and overridden the DrawBoarder method to not draw anything but that seems to apply to all of the contained buttons as well (i.e the menu on drop down buttons are also drawn without a border).

So I'm stuck. What's the best way to draw transparent the entire ToolStrip but leave the buttons alone?


回答1:


protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
    if( e.ToolStrip.GetType().Name != "MyCustomToolStrip" )
    {
        base.OnRenderToolStripBorder(e);
    }
}



回答2:


I have tried just overriding the OnRenderToolStripBorder method and it seems it doesn't affect the buttons at all. Have you tried it like this?

public class TestStripRenderer : ToolStripProfessionalRenderer
{   
    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
    }
}



回答3:


Since you are trying to make the toolstrip hidden but keep the buttons, I have to put this out there.

Do you even need the toolstrip?

It might be better if you just used buttons in the application without the seemingly unneeded toolstrip.



来源:https://stackoverflow.com/questions/5245929/c-sharp-toolstrip-is-transparent-but-border-is-still-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!