如何在winforms中更改标题栏颜色 [英] How to change titlebar color in winforms
本文介绍了如何在winforms中更改标题栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改WinForms中的标题栏颜色C#,Visual Studio,白色的默认颜色
我尝试过:
How to change Titlebar color in WinForms C#, Visual Studio, Default color in White
What I have tried:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace TitleBarColorChange
{
public partial class Form1 : Form
{
[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);
g.FillRectangle(Brushes.Green, new Rectangle(0, 0, 4800, 30));
g.Flush();
ReleaseDC(m.HWnd, hdc);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.BackColor = System.Drawing.Color.MistyRose;
this.StartPosition = FormStartPosition.CenterScreen;
}
}
}
我发现此代码但没有工作
I found this code but not Working
推荐答案
Winforms SkinFramework [ ^ ]
这篇关于如何在winforms中更改标题栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文