[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
protected override void WndProc(ref Message m)
{
const int WM_NCPAINT = 0x85;
const int WM_NCACTIVATE = 0x0086;
if (m.Msg == WM_NCPAINT)
{
DrawTitleBar(true);
}
else
{
base.WndProc(ref m);
if (m.Msg == WM_NCACTIVATE)
{
DrawTitleBar(false);
}
}
}
Bitmap bmp = new Bitmap(@"D:\Download\a.jpg");
private void DrawTitleBar(bool drawForm)
{
IntPtr hdc = GetWindowDC(this.Handle);
using (Graphics g = Graphics.FromHdc(hdc))
{
g.SmoothingMode = SmoothingMode.HighQuality;
if (drawForm)
{
Bitmap bm = new Bitmap(this.Width, this.Height);
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
this.DrawToBitmap(bm, rect);
g.DrawImage(bm, rect);
}
g.DrawImage(bmp, 0, 0, this.Width-110, SystemInformation.CaptionHeight+8);
}
ReleaseDC(this.Handle, hdc);
}