using System;
using System.Drawing;
using System.Windows.Forms;
public class CustomForm : Form
{
private Panel headerPanel;
public CustomForm()
{
// Remove default title bar
this.FormBorderStyle = FormBorderStyle.None;
this.Size = new Size(500, 300);
// Create a custom header panel
headerPanel = new Panel
{
Height = 40,
Dock = DockStyle.Top,
BackColor = Color.DarkBlue // Change to any color
};
this.Controls.Add(headerPanel);
// Enable dragging
headerPanel.MouseDown += HeaderPanel_MouseDown;
}
private void HeaderPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.Capture = false;
Message m = Message.Create(this.Handle, 0xA1, (IntPtr)2, IntPtr.Zero);
this.WndProc(ref m);
}
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new CustomForm());
}
}
If DwmSetWindowAttribute
doesn't work, you can remove the default title bar and create a custom header.
🔹 Steps:
- Set FormBorderStyle to None.
- Add a Panel at the top as the header.
- Handle form dragging manually.
Sign up here with your email
ConversionConversion EmoticonEmoticon