如何改变winForm(C#)标题栏的颜色? 前面已结贴,现在又发现新问题了

chenzhirun 2007-03-09 11:35:36
原问题内容及解答:http://community.csdn.net/Expert/topic/5371/5371386.xml?temp=.7900812
现在发现的问题是如果窗体的isMdiContainer为false的时候一切正常,但是isMdiContainer为true的时候标题拦无论如何都不改变颜色,用GDI也绘不上文字。也就是说窗体为多文挡界面的时候就不行了。望高手帮忙。急啊!万谢了。
...全文
1740 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
gsmlove 2008-12-19
  • 打赏
  • 举报
回复
mark
LeoMaya 2007-03-12
  • 打赏
  • 举报
回复
mark
cnming 2007-03-12
  • 打赏
  • 举报
回复
mark
xu_2007 2007-03-10
  • 打赏
  • 举报
回复
学习
北京的雾霾天 2007-03-10
  • 打赏
  • 举报
回复
在WndProc方法中添加如下的一个分支就可以了:
if (m.Msg == 0xa3)
{
return;//双击不最大化窗口
}
chenzhirun 2007-03-10
  • 打赏
  • 举报
回复
问题解决了。无言的感谢。希望平民百姓能加我为好友 msn:chenzhirun@hotmail.com
北京的雾霾天 2007-03-09
  • 打赏
  • 举报
回复
isMdiContainer为true的时候标题拦无论如何都不改变颜色,用GDI也绘不上文字
------------------------------------------------------------------------

窗口是有默认的标题栏,还是没有呢?
我说的是没有标题的栏窗体啊.
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
to:平民百姓.
啊?我也是vs2005啊。怎么会这样了?把你的代码给我发一份好吗?
email:czr3819@sohu.com
北京的雾霾天 2007-03-09
  • 打赏
  • 举报
回复
是isMdiContainer为true的时就不起作用了。
---------
不是啊,我这里都没有问题啊(VS2005).
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
to:平民百姓。
是的啊,formBorderStyle设为none,标题拦就自动隐藏了。单文挡窗体的时候就是这样的都没问题。但是isMdiContainer为true的时就不起作用了。
北京的雾霾天 2007-03-09
  • 打赏
  • 举报
回复
不要标题,把标题隐藏掉!
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
TO:平民百姓
对了,加上你的protected override void OnPaint(PaintEventArgs e)就好了。还有个问题,这个新指定的标题拦如何响应在其上的双击事件了,这个标题拦上双击时窗体会最大化,我想让窗体固定大小,也就是不要响应双击事件。这该怎么处理了?
你用的这些方法都是vc++的吧,我在msdn上都查不到啊。
非常感谢平民百姓了。
jinglong6511 2007-03-09
  • 打赏
  • 举报
回复
up
北京的雾霾天 2007-03-09
  • 打赏
  • 举报
回复
因为当窗体是MdiParent的时候它的背景是系统指定的,因此,你需要在合适的时候对它进行重新绘制才行.
北京的雾霾天 2007-03-09
  • 打赏
  • 举报
回复
给你的窗体添加如下的方法以便在需要的时候重绘:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.Clear(this.BackColor);
}
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
怎么没人关心这个问题了?自己顶一下
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
frmMove.cs文件如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace clientLearning.Rubish
{
public partial class frmMove : Form
{
public frmMove()
{
InitializeComponent();
}
internal static int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息
internal static IntPtr HTCLIENT = (IntPtr)0x1;//工作区
internal static IntPtr HTCAPTION = (IntPtr)0x2; //标题栏


protected override void WndProc(ref Message m)
{
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if (m.Result == HTCLIENT)
{
m.Result = HTCAPTION;//模拟标题栏,移动或双击可以最大或最小化窗体
}
}
else
{
base.WndProc(ref m);

}
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();

}


public override bool PreProcessMessage(ref Message msg)
{
MessageBox.Show(msg.ToString());
return true;
}

private void frmMove_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics g = e.Graphics;
SolidBrush myBrush = new SolidBrush(Color.Blue);

Font myFont2 = new Font("Times New Roman", 10);
SolidBrush c_myBrush = new SolidBrush(Color.Black);


g.DrawString("大猫", myFont2, myBrush, 0, 0);


}

private void button_close_Click(object sender, EventArgs e)
{
this.Close();
}

private void button_min_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}

private void button_min_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics g = e.Graphics;
SolidBrush myBrush = new SolidBrush(Color.Blue);
Font myFont1 = new Font("Times New Roman", 30);
Font myFont2 = new Font("Times New Roman", 10);
SolidBrush c_myBrush = new SolidBrush(Color.Black);
g.DrawString("*", myFont2, myBrush, 0, 0);


}

private void button_close_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics g = e.Graphics;
SolidBrush myBrush = new SolidBrush(Color.Blue);
Font myFont1 = new Font("Times New Roman", 30);
Font myFont2 = new Font("Times New Roman", 10);
SolidBrush c_myBrush = new SolidBrush(Color.Black);
g.DrawString("X", myFont2, myBrush, 0, 0);

}




}
}
//////////////////////////////////////
frmMove.Designer代码如下:
namespace clientLearning.Rubish
{
partial class frmMove
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button_close = new System.Windows.Forms.Button();
this.button_min = new System.Windows.Forms.Button();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// button_close
//
this.button_close.Location = new System.Drawing.Point(491, 5);
this.button_close.Name = "button_close";
this.button_close.Size = new System.Drawing.Size(16, 14);
this.button_close.TabIndex = 3;
this.button_close.UseVisualStyleBackColor = true;
this.button_close.Click += new System.EventHandler(this.button_close_Click);
this.button_close.Paint += new System.Windows.Forms.PaintEventHandler(this.button_close_Paint);
//
// button_min
//
this.button_min.Location = new System.Drawing.Point(469, 5);
this.button_min.Name = "button_min";
this.button_min.Size = new System.Drawing.Size(16, 14);
this.button_min.TabIndex = 4;
this.button_min.UseVisualStyleBackColor = true;
this.button_min.Click += new System.EventHandler(this.button_min_Click);
this.button_min.Paint += new System.Windows.Forms.PaintEventHandler(this.button_min_Paint);
//
// splitContainer1
//
this.splitContainer1.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 20);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Size = new System.Drawing.Size(520, 292);
this.splitContainer1.SplitterDistance = 173;
this.splitContainer1.TabIndex = 5;
//
// frmMove
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.DarkOrange;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.ClientSize = new System.Drawing.Size(520, 312);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.button_min);
this.Controls.Add(this.button_close);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "frmMove";
this.Padding = new System.Windows.Forms.Padding(0, 20, 0, 0);
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmMove";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmMove_Paint);
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Button button_close;
private System.Windows.Forms.Button button_min;
private System.Windows.Forms.SplitContainer splitContainer1;
}
}
////////////////////////////////
这里如果frmMove的isMdiContainer如果为一切工作正常,否则窗体变暗灰,如论怎样设置它的背景色都不变了。
chenzhirun 2007-03-09
  • 打赏
  • 举报
回复
窗口原有标题拦,但是我把FormBorderStyle设为 none 就没有标题拦了。我这样作的算不算没有标题拦的窗体了?
没法下载,到这里折腾一把试试。 本文由abc2253130贡献 doc文档可能在WAP端浏览体验不佳。建议您优先选择TXT,或下载源文件到本机查看。 C#WINFORM)学习 一、 C#基础 基础 类型和变量 类型和变量 类型 C# 支持两种类型:“值类型”和“引用类型”。值类型包括简单类型(如 char、int 和 float 等)、枚举类型和结构类型。引用类型包括类 (Class)类 型、接口类型、委托类型和数组类型。 变量的类型声明 变量的类型声明 每个变量必须预先声明其类型。如 int a; int b = 100; float j = 4.5; string s1; 用 object 可以表示所有的类型。 预定义类型 下表列出了预定义类型,并说明如何使用。 类型 object 说明 所有其他类型的最终 基类型 字符串类型; 字符串是 Unicode 字符序列 8 位有符号整型 16 位有符号整型 32 位有符号整型 64 位有符号整型 示例 object o = null; 范围 string sbyte short int long string s = "hello"; sbyte val = 12; short val = 12; int val = 12; long val1 = 12; -128 到 127 -32,768 到 32,767 -2,147,483,648 2,147,483,647 -9,223,372,036,854,775,808 到 第1页 C#WINFORM)学习 long val2 = 34L; 到 9,223,372,036,854,775,807 byte ushort 8 位无符号整型 16 位无符号整型 byte val1 = 12; ushort val1 = 12; uint val1 = 12; uint 32 位无符号整型 uint val2 = 34U; ulong val1 = 12; ulong val2 = 34U; ulong 64 位无符号整型 ulong val3 = 56L; ulong val4 = 78UL; float 单精度浮点型 float val = 1.23F;7 位 double val1 = 1.23; double 双精度浮点型 double val2 = ±5.0 × 10?324 ±1.7 × 10 308 0 到 255 0 到 65,535 0 到 4,294,967,295 0 到 18,446,744,073,709,551,615 ±1.5 × 10?45 ±3.4 × 10 38 到 到 4.56D;15-16 布尔型;bool 值或为 真或为假 字符类型;char 值是 一个 Unicode 字符 精确的小数类型, 具有 28 个有效数字 bool val1 = true; bool val2 = false; char val = 'h'; decimal val = bool char decimal DateTime ±1.0 × 10?28 ±7.9 × 10 28 到 1.23M;28-29 变量转换 简单转换: float f = 100.1234f; 可以用括号转换: short s = (short)f 也可以利用 Convert 方法来转换: string s1; s1=Convert.ToString(a); MessageBox.Show(s1); 常用 Convert 方法有: 第2页 C#WINFORM)学习 C# Convert.ToBoolean Convert.ToByte Convert.ToChar Convert.ToDateTime Convert.ToDecimal Convert.ToDouble Convert.ToInt16 Convert.ToInt32 Convert.ToInt64 Convert.ToSByte Convert.ToSingle Convert.ToString Convert.ToUInt16 Convert.ToUInt32 Convert.ToUInt64 备注 Math 类 常用科学计算方法: C# Math.Abs Math.Sqrt Math.Ro
说明: 这是本人效仿126邮箱界面在美工的配合下做的一公用界面、基本上适合很多信息管理系统的界面要求。本人的CSS和JAVASCIRPT的功底有限,开发的东西难免会有些BUG或者很肤浅的地方,希望和朋友们一起探讨解决其中的一些问题。也非常希望高手们优化我JS。 功能介绍: 1、可以换皮肤、其中住框架、具体页面可以统一使用皮肤。 2、tab页标题有右键菜单,开、全屏打开,刷。双击标题也可以刷。 3、可以收放菜单栏。 使用方法: 基本上主框架页面不需要作任何的变动了,直接就可以用,就不讲了。 在这里主要讲一下使用tabControl: tabControl开一个页面实际上是通过JS在主显示区域建立一个iframe 把这个iframe的src 指向我们指定的页面。 本源码由16Aspx调测并整理 商业版资源请在作者或者16Aspx授权范围内使用,否则后果自负! 如需转载免费版请注明作者信息及来源,以示对他人劳动成果的尊重! 获得更有效最的帮助技术支持看这里:http://www.16aspx.com/ ╭═══════════════╮ ║ .Net源码 控件专业站 ║ ╭══════┤ http://www.16aspx.com ├═════╮ ║ ║论坛:http://www.16aspx.com/forumindex.aspx ║ ║ ╰═══════════════ ╯ ║  ║ ║ ║ ║  ║16Aspx声明: ║ ║ 1) 本站不保证所提供软件或程序的完整性和安全性。 ║ ║ 2) 转载本站提供的资源请勿删除本说明文件。 ║ ║ 3) 本站源码为网上搜集或网友提供,如果涉及或侵害到您的版║ ║ 请立即写信通知我们。 ║ ║ 4) 本站提供代码只可供研究使用,请在下载24小时内删除, ║ ║ 切勿用于商业用途,由此引起一切后果与本站无关。 ║ ║ 5) 源码后续升级或修补,我们会在该源码评论中发布! ║  ║ ║ ║ ║  ║项目承接:Asp.Net网站,Asp.Net管理系统开发,Winform系统开发 ║ ║ Silverlight、WPF开发,各类管理系统工具开发 ║ ║ ║ ║网站广告投放:QQ: 330199865,Email: amomzk@hotmail.com ║ ║ ║ ║ 本站专注于C# .NET技术讨论 ║ ║ 联系方式 : amomzk@hotmail.com ║ ║ ╭───────────────────────╮ ║ ╰══┤ .Net源码专业站 http://www.16aspx.com ├══╯ ╰───────────────────────╯ 友情提示: 一般数据库文件默认在DB_16aspx文件夹下 更多使用帮助和协议请浏览http://www.16aspx.com/ 以上相关内容变更请以16Aspx官方网站最终显示为准

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧