According to a lot of questions here on SO, the best way to make the background of a form transparent is to set it to a fairly unused color (like Magenta) then set the form's TransparencyKey
to that color.
this.BackColor = Color.Magenta;
this.TransparencyKey = Color.Magenta;
That part works fine. The problem that I'm running into is that it works fine except behind a MenuStrip. A semi-transparent background in the MenuStrip + transparent background in the form ends up like this:
That's what the MenuStrip looks like. The part where it turns magenta is when the MenuStrip itself is set to be semi-transparent.
This is what my form initialization function looks like:
public frmMain() {
this.TransparencyKey = Color.Magenta;
InitializeComponent();
this.BackColor = Color.Magenta;
if(Properties.Settings.Default.windowTheme == 0) { // theme is light
menuStrip.Renderer = new ToolStripProfessionalRenderer(new LightTheme());
}
else if(Properties.Settings.Default.windowTheme == 1) {
menuStrip.Renderer = new ToolStripProfessionalRenderer(new DarkTheme());
}
menuStrip.Invalidate();
}
And my custom renderer for the MenuStrip (colors are just for testing right now):
public class LightTheme: ProfessionalColorTable {
public override Color MenuItemSelected {
get { return Color.FromArgb(255, Color.Yellow); }
}
public override Color MenuStripGradientBegin {
get { return Color.FromArgb(255, Color.Black); }
}
public override Color MenuStripGradientEnd {
get { return Color.FromArgb(0, Color.Gainsboro); }
}
}
What I'm really trying to accomplish here is having the form transparent and part of the MenuStrip transparent so you can see the desktop underneath it. Is there a better way to do it, or a way to fix this?