Click here to Skip to main content
15,846,571 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am changing color of title bar using following code but when I maximise my or resize form then control box not appear. when I mouse over then again control box will appear so any one know what is the issue in following code?

[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDc);
[DllImport("User32.dll")]

private static extern IntPtr GetWindowDC(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
const int WM_NCPAINT = 0x85;
if (m.Msg == WM_NCPAINT)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
SolidBrush b = new SolidBrush(Color.FromArgb(0, 116, 212));
g.FillRectangle(b, new Rectangle(0, 0, 4800, 30));
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = Color.FromArgb(214, 236, 246);
this.StartPosition = FormStartPosition.CenterScreen;
}

What I have tried:

I tried above code. and many other code but I face same issue with control box.
Posted
Updated 14-Sep-16 22:09pm

1 solution

Simple: you do the base NCPaint which I suspect handles it's sub controls for the Control Box and related controls and then paint over them with your new colour.
I would suggest that instead of trying to just paint it you have a look at applying a Skin to the whole form. There are several ways to do that, but most do cost money:
Skin engine. C++, C#, Visual Basic skinning[^]
VisualStyler for Windows Forms .NET extension[^]
Google will find you more: skinning c# - Google Search[^]
 
Share this answer
 
Comments
Member 924477 8-Feb-20 2:13am    
Any solution for the control box to appear ?.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900