如何在c#winforms中更改表单标题栏的颜色

如何在c#winforms中更改表单标题栏的颜色

本文介绍了如何在c#winforms中更改表单标题栏的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Hai Friends .. 
我需要一些代码更改颜色 标题栏的 表单 c#winforms?
实际上我试过 使用 USER32.dll..its 更改颜色 标题栏...它正好覆盖标题栏 Give Color





我的代码片段是这样的:



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Windows.Forms;
使用 System.Runtime.InteropServices;

命名空间 TitleBarColorChange
{
public partial class Form1:Form
{
[DllImport( user32.dll)]
static extern int ReleaseDC( IntPtr hWnd, IntPtr hDc);

[DllImport( User32.dll)]
私有 静态 extern IntPtr GetWindowDC( IntPtr hWnd);

public Form1()
{
InitializeComponent();
}
受保护 覆盖 void WndProc( ref 消息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 矩形( 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;


}
}
}



任何人都可以帮助我....



提前谢谢你

解决方案

Hai Friends..
I Need Some Code  to change the color of the title bar of a form in c# winforms ?
Actually I Tried by Using USER32.dll..its not Changing The Color Of The Title Bar...Its Just Covering The Title Bar With The Give Color



My Code Snippet Is This:

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;
          
            
        }
    }
}


Can any one Pls Help Me....

Thanking You In Advance

解决方案


这篇关于如何在c#winforms中更改表单标题栏的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:34