如何改变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也绘不上文字。也就是说窗体为多文挡界面的时候就不行了。望高手帮忙。急啊!万谢了。
...全文
1900 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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 就没有标题拦了。我这样作的算不算没有标题拦的窗体了?

111,098

社区成员

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

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

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