#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
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
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货