Hi

removes the default title bar and replaces it with a custom panel

 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:

  1. Set FormBorderStyle to None.
  2. Add a Panel at the top as the header.
  3. Handle form dragging manually.
Previous
Next Post »