When I resize the form. the border flickers and the old title bar shows up.
Also I can't figure out how to custom draw the control box buttons(close,maximize, etc.)
Here is the code I use for non-client drawing:
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern void DisableProcessWindowsGhosting();
[DllImport("UxTheme.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr SetWindowTheme(IntPtr hwnd, string pszSubAppName, string pszSubIdList);
protected override void WndProc(ref Message m)
{
const int WM_NCPAINT = 0x85;
base.WndProc(ref m);
if (m.Msg == WM_ERASEBKGND)
m.Result = new IntPtr(0);
if (m.Msg == WM_NCPAINT || m.Msg == WM_IME_NOTIFY || m.Msg == WM_SIZE || m.Msg == WM_NCACTIVATE)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
Rectangle rect = new Rectangle(new Point(0, 0), new Size(this.Width, 23));
LinearGradientBrush linearBrush = new LinearGradientBrush(rect, Color.FromArgb(134, 174, 226), Color.FromArgb(178, 204, 239), LinearGradientMode.Vertical);
rect.Height = 7;
LinearGradientBrush linearBrush1 = new LinearGradientBrush(rect, Color.FromArgb(170, 199, 239), Color.FromArgb(157, 194, 249), LinearGradientMode.Vertical);
Color col = Color.FromArgb(178, 204, 239);
Rectangle BorderLeft = new Rectangle(0, 23, 3, this.Height - 23);
g.FillRectangle(new SolidBrush(col), BorderLeft);
Rectangle BorderRight = new Rectangle(this.Width - 4, 23, 4, this.Height - 23);
g.FillRectangle(new SolidBrush(col), BorderRight);
Rectangle BorderBottom = new Rectangle(0, this.Height - 4, this.Width, 4);
g.FillRectangle(new SolidBrush(col), BorderBottom);
g.FillRectangle(linearBrush, 0, 0, this.Width, 23);
g.FillRectangle(linearBrush1, 0, 0, this.Width, 7);
Rectangle clientRect = this.ClientRectangle;
clientRect.Location = new Point(3, 23);
g.FillRectangle(new SolidBrush(BackColor), clientRect);
if (this.ShowIcon != false && this.Icon != null)
{
g.DrawImage(this.Icon.ToBitmap(), 6, 5, 16, 16);
}
g.DrawString(this.Text, this.Font, new SolidBrush(Color.Black), 25, 6);
foreach (Control control in this.Controls)
control.Invalidate();
g.Flush();
g.Dispose();
linearBrush.Dispose();
linearBrush1.Dispose();
ReleaseDC(m.HWnd, hdc);
}
}
}
sometimes the control box buttons show up.
Thanks in advance.

New Topic/Question
Reply




MultiQuote





|