This is sample:
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public partial class Form1 : Form
{
private readonly MenuStrip menuStrip = new MenuStrip();
private readonly ToolStripMenuItem mnuFile = new ToolStripMenuItem();
private readonly ToolStripMenuItem mnuEdit = new ToolStripMenuItem();
private readonly ToolStripMenuItem mnuFileOpen = new ToolStripMenuItem();
private readonly ToolStripMenuItem mnuFileExit = new ToolStripMenuItem();
private readonly Color menuItemBackColor = Color.White;
public Form1() {
InitializeComponent();
Opacity = 0.7d;
BackColor = Color.Gray;
menuStrip.SuspendLayout();
menuStrip.Font = new Font("Arial", 12F, FontStyle.Bold);
menuStrip.ForeColor = Color.White;
menuStrip.BackColor = Color.Transparent;
menuStrip.Renderer = new CustomRenderer();
mnuFile.Text = "File(&F)";
mnuFile.DropDownOpened += MnuFile_DropDownOpened;
mnuEdit.Text = "Edit(&E)";
mnuFileOpen.Text = "Open(&O)";
mnuFileExit.BackColor = menuItemBackColor;
mnuFileExit.Text = "Exit(&X)";
mnuFileExit.Click += MnuFileExit_Click;
mnuFileExit.BackColor = menuItemBackColor;
mnuFile.DropDownItems.AddRange(new ToolStripItem[] { mnuFileOpen, mnuFileExit });
menuStrip.Items.AddRange(new ToolStripItem[] { mnuFile, mnuEdit });
Controls.Add(menuStrip);
menuStrip.ResumeLayout();
}
private void MnuFile_DropDownOpened(object sender, EventArgs e) {
var item = (ToolStripMenuItem)sender;
IntPtr hwnd = item.DropDown.Handle;
int styleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
if ((styleEx & WS_EX_LAYERED) == 0) {
SetWindowLong(hwnd, GWL_EXSTYLE, styleEx | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, 0, 180, LWA_ALPHA);
}
}
private void MnuFileExit_Click(object sender, EventArgs e) {
Close();
}
class CustomRenderer : ToolStripRenderer
{
public Color SelectionBackColor { get; set; } = Color.Black;
public Color SelectionForeColor { get; set; } = Color.White;
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
Color backColor = e.Item.Selected ? SelectionBackColor : e.Item.BackColor;
using (var backBrush = new SolidBrush(backColor)) {
e.Graphics.FillRectangle(backBrush, bounds);
}
}
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
e.TextColor = e.Item.Selected ? SelectionForeColor : e.Item.ForeColor;
base.OnRenderItemText(e);
}
}
const int WS_EX_LAYERED = 0x80000;
const int GWL_EXSTYLE = -20;
const int LWA_COLORKEY = 0x00000001;
const int LWA_ALPHA = 0x00000002;
[DllImport("user32.dll")]
static extern bool SetLayeredWindowAttributes(
IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
[DllImport("user32.dll")]
static extern int GetWindowLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
}