我只想对我的应用程序的windows窗体标题栏重新着色,我在上找到了这段代码
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("User32.dll")]
private static extern IntPtr GetWindowDC(IntPtr hWnd);
protected override void WndProc(ref System.Windows.Forms.Message m)
{
const int WM_NCPAINT = 0x85;
base.WndProc(ref m);
if (m.Msg == WM_NCPAINT)
{
IntPtr hdc = GetWindowDC(m.HWnd);
if ((int)hdc != 0)
{
Graphics g = Graphics.FromHdc(hdc);
g.FillRectangle(Brushes.Green, 10, 0, 4800, 23);
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
但我不知道如何触发它,你能帮我吗?
我所做的是将FormBorderStyle属性设置为None,然后使用flowLayoutPanel作为标题栏,设置鼠标事件和添加最小化/关闭按钮。