我设计了两个窗体,在form2中有一个一个命令按钮,执行后,可改变form1下的文本框的背景色.但是,做完后,我单步执行,代码执行起来没有问题,可form1文本框的颜色却没变.什么原因呀?高手给指点下.没积分了,版主莫删我的帖子哦.
以下是form2按钮下的部分代码:private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
const string BackColW ="白色";
const string BackColB = "黑色";
const string BackColBL="蓝色";
const string BackColR="红色";
const string BackColG="绿色";
string BCC;
BCC = comboBox1.Text;
if (BCC == BackColW)
frm1.txtContent.BackColor = Color.White;
else if (BCC == BackColB)
frm1.txtContent.BackColor = Color.Black;
else if (BCC == BackColBL)
frm1.txtContent.BackColor=Color.Blue;
else if (BCC == BackColR)
frm1.txtContent.BackColor=Color.Red;
this.Dispose();
来源: http://www.programbbs.com/bbs/view14-19010-1.htm
以下是form2按钮下的部分代码:private void button1_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
const string BackColW ="白色";
const string BackColB = "黑色";
const string BackColBL="蓝色";
const string BackColR="红色";
const string BackColG="绿色";
string BCC;
BCC = comboBox1.Text;
if (BCC == BackColW)
frm1.txtContent.BackColor = Color.White;
else if (BCC == BackColB)
frm1.txtContent.BackColor = Color.Black;
else if (BCC == BackColBL)
frm1.txtContent.BackColor=Color.Blue;
else if (BCC == BackColR)
frm1.txtContent.BackColor=Color.Red;
this.Dispose();
来源: http://www.programbbs.com/bbs/view14-19010-1.htm
解决方案 »
- C#可以访问继承自IUnknown接口的com吗?
- 简单的正则表达?
- 如何实现用 dategridview绑定数据,但是不用它来更新数据呢?
- 哪个有 visual studio 2005 team suite 的英文版
- 有没有曾经部署过.net虚拟主机的人阿?
- 自己做控件的问题
- 数据库连接问题
- 我应该如何在listview中添加事件处理方法,比如listView1_DoubleClick,急!!!!!!!!!
- 急求类似于组织结构图的那种树形控件!!!!
- 使用了classA:classB,System.Security.Principal.IIdentity报错!
- 如何将一个表中的所有索引找出并删除掉?
- WebConfig读取问题
你这里的frm1是新的,跟原来的没关系。当然不能改变上面的控件背景色了
/// <summary>
/// 查找窗体的MdiClient控件并返回
/// </summary>
/// <param name="f">查找MdiClient控件的窗体</param>
/// <returns>查找到的MdiClient控件</returns>
public static System.Windows.Forms.MdiClient
GetMdiClient(System.Windows.Forms.Form f)
{
foreach (System.Windows.Forms.Control c in f.Controls)
if (c is System.Windows.Forms.MdiClient)
return (System.Windows.Forms.MdiClient) c;
return null;
}//查找MdiClient
System.Windows.Forms.MdiClient mc = GetMdiClient(this);
if (mc != null)
{
//更改背景色,重新描绘
mc.BackColor = this.BackColor;
mc.Invalidate();
}