C#中如何改变对话框的标题栏颜色? 各位想请教下,在C#中如何改变对话框的标题栏颜色?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #region 改变窗口样式 #if !DEBUG [DllImport ("User32.dll")] private static extern IntPtr GetWindowDC(IntPtr hwnd); [DllImport ("User32.dll")] private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc); protected override void WndProc(ref Message m) ...{ base.WndProc(ref m); switch(m.Msg) ...{ case 0x86://WM_NCACTIVATE goto case 0x85; case 0x85://WM_NCPAINT ...{ IntPtr hDC = GetWindowDC(m.HWnd); //把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了 Graphics gs = Graphics.FromHdc(hDC); 处理色彩#region 处理色彩 int ibox = 1; if (this.MaximizeBox) ibox ++; if (this.MinimizeBox) ibox ++; //得到相关背景图片 Image imgpm = Image.FromFile( Application.StartupPath+ @"Main.bmp"); //gs.DrawImage(imgbg,3,0,this.Width - (ibox * iBoxWidh),SystemInformation.CaptionHeight + 2); //显示背景图片 //标题栏显示背景颜色 int xPos = this.Width - iBoxWidh * ibox - 2 - ibox*3; Rectangle excludeRect; //标题栏中不需要填充的位置 for(int i=0;i<ibox;i++) ...{ if( i>0) ...{ xPos = xPos + iBoxWidh + 2; } excludeRect = new Rectangle(xPos, 5, iBoxWidh, iBoxWidh+1); gs.ExcludeClip(excludeRect); } //背景区域 Rectangle rBackground = new Rectangle(0,0,this.Width,SystemInformation.CaptionHeight+3); //背景颜色 上下渐变 System.Drawing.Drawing2D.LinearGradientBrush bBackground = new System.Drawing.Drawing2D.LinearGradientBrush(rBackground, Color.FromArgb(100,145,175), Color.FromArgb(45,80,120),LinearGradientMode.Vertical); //标题栏填充背景颜色 gs.FillRectangle(bBackground,rBackground ); //显示图标文件 gs.DrawImage(imgpm,4,4,24,24); #endregion StringFormat strFmt = new StringFormat(); //strFmt.Alignment = StringAlignment.Center; //strFmt.LineAlignment = StringAlignment.Center; //gs.DrawString(this.Text, this.Font, Brushes.BlanchedAlmond, m_rect, strFmt); //设置标题字体 Font drawFont = new Font("宋体", 10,System.Drawing.FontStyle.Bold); //设置标题颜色 SolidBrush drawBrush = new SolidBrush(Color.White); //重画标题 gs.DrawString(this.Text, drawFont, drawBrush, 30,8); gs.Dispose(); //释放GDI资源 ReleaseDC(m.HWnd, hDC); break; } case 0xA1://WM_NCLBUTTONDOWN ...{ Point mousePoint = new Point((int)m.LParam); mousePoint.Offset(-this.Left, -this.Top); // if(m_rect.Contains(mousePoint)) // { // // MessageBox.Show("hello"); // // } break; } } } #endif #endregion 请问下这个是不是C#调用C++中的API的? 顺便问一下怎么改MesseageBox的样子 还有什么消息提示框,错误提示框的样子 改 messagebox的样子也是需要重新画的 购物车问题 C#反射机制的问题 .NET中关于作用域的划分 怎么抓不到PictureBox 用FileSystemWatcher怎么监视多个文件夹,不知道有几个文件夹,不固定,动态的. 请教关于listbox的问题 菜鸟求救!! 大家在深圳一般是如何找工作的 WPF ACCESS数据库 操作问题 架构设计的高级问题 !!!有请孟子,大灰狼,SP123等等牛人。 如何通过软件登陆网站发帖 关于Remoting
private static extern IntPtr GetWindowDC(IntPtr hwnd); [DllImport ("User32.dll")]
private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
protected override void WndProc(ref Message m) ...{
base.WndProc(ref m);
switch(m.Msg)
...{ case 0x86://WM_NCACTIVATE goto case 0x85; case 0x85://WM_NCPAINT
...{
IntPtr hDC = GetWindowDC(m.HWnd);
//把DC转换为.NET的Graphics就可以很方便地使用Framework提供的绘图功能了
Graphics gs = Graphics.FromHdc(hDC); 处理色彩#region 处理色彩 int ibox = 1; if (this.MaximizeBox) ibox ++;
if (this.MinimizeBox) ibox ++; //得到相关背景图片
Image imgpm = Image.FromFile( Application.StartupPath+ @"Main.bmp");
//gs.DrawImage(imgbg,3,0,this.Width - (ibox * iBoxWidh),SystemInformation.CaptionHeight + 2); //显示背景图片 //标题栏显示背景颜色
int xPos = this.Width - iBoxWidh * ibox - 2 - ibox*3; Rectangle excludeRect;
//标题栏中不需要填充的位置
for(int i=0;i<ibox;i++)
...{
if( i>0)
...{
xPos = xPos + iBoxWidh + 2;
}
excludeRect = new Rectangle(xPos, 5, iBoxWidh, iBoxWidh+1);
gs.ExcludeClip(excludeRect);
}
//背景区域
Rectangle rBackground = new Rectangle(0,0,this.Width,SystemInformation.CaptionHeight+3);
//背景颜色 上下渐变
System.Drawing.Drawing2D.LinearGradientBrush bBackground
= new System.Drawing.Drawing2D.LinearGradientBrush(rBackground, Color.FromArgb(100,145,175), Color.FromArgb(45,80,120),LinearGradientMode.Vertical); //标题栏填充背景颜色
gs.FillRectangle(bBackground,rBackground );
//显示图标文件
gs.DrawImage(imgpm,4,4,24,24); #endregion
StringFormat strFmt = new StringFormat(); //strFmt.Alignment = StringAlignment.Center;
//strFmt.LineAlignment = StringAlignment.Center; //gs.DrawString(this.Text, this.Font, Brushes.BlanchedAlmond, m_rect, strFmt);
//设置标题字体
Font drawFont = new Font("宋体", 10,System.Drawing.FontStyle.Bold);
//设置标题颜色
SolidBrush drawBrush = new SolidBrush(Color.White);
//重画标题
gs.DrawString(this.Text, drawFont, drawBrush, 30,8); gs.Dispose(); //释放GDI资源 ReleaseDC(m.HWnd, hDC);
break; } case 0xA1://WM_NCLBUTTONDOWN
...{ Point mousePoint = new Point((int)m.LParam); mousePoint.Offset(-this.Left, -this.Top); // if(m_rect.Contains(mousePoint))
// {
//
// MessageBox.Show("hello");
//
// } break; }
}
}
#endif #endregion