Hi

change background color of the form header area in windows form c#

 using System;

using System.Drawing;

using System.Runtime.InteropServices;

using System.Windows.Forms;


public class MyForm : Form

{

    const int DWMWA_CAPTION_COLOR = 35;


    [DllImport("dwmapi.dll")]

    public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);


    public MyForm()

    {

        this.Load += (s, e) => ChangeTitleBarColor(Color.DarkBlue);

    }


    private void ChangeTitleBarColor(Color color)

    {

        int colorValue = color.R | (color.G << 8) | (color.B << 16);

        DwmSetWindowAttribute(this.Handle, DWMWA_CAPTION_COLOR, ref colorValue, sizeof(int));

    }


    [STAThread]

    public static void Main()

    {

        Application.EnableVisualStyles();

        Application.Run(new MyForm());

    }

}


Previous
Next Post »