using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class MyForm : Form
{
const int DWMWA_CAPTION_COLOR = 35; // Title bar background color
const int DWMWA_TEXT_COLOR = 36; // Title bar text color
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
public MyForm()
{
this.Text = "Custom Title Bar"; // Set Window Title
this.Load += (s, e) =>
{
ChangeTitleBarColor(Color.DarkBlue); // Background
ChangeTitleTextColor(Color.White); // Text Color
};
}
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));
}
private void ChangeTitleTextColor(Color color)
{
int colorValue = color.R | (color.G << 8) | (color.B << 16);
DwmSetWindowAttribute(this.Handle, DWMWA_TEXT_COLOR, ref colorValue, sizeof(int));
}
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MyForm());
}
}
Sign up here with your email
ConversionConversion EmoticonEmoticon