C#中如何用一个窗体中的按钮控制你一个窗体的背景颜色?还有其他的属性怎么控制?
展开全部
楼主帮你写了段代码 添加两个窗体 c# winform form1
form2 form1上添加一个按钮用来弹出form2 form2上也添加一个按钮用来更改form1的颜色
代码如下
form1代码
namespace WindowsApplication1
{ public delegate void BackClo();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void changc()
{
if (BackColor == Color.Gray)
{
this.BackColor = Color.Green;
}
else
{
this.BackColor = Color.Gray;
}
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(new BackClo(changc));
f2.ShowDialog();
}
}
}
form2代码
namespace WindowsApplication1
{
public partial class Form2 : Form
{
BackClo at;
public Form2(BackClo bc)
{
InitializeComponent();
at = bc;
}
private void button1_Click(object sender, EventArgs e)
{
at();
}
}
}
form2 form1上添加一个按钮用来弹出form2 form2上也添加一个按钮用来更改form1的颜色
代码如下
form1代码
namespace WindowsApplication1
{ public delegate void BackClo();
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void changc()
{
if (BackColor == Color.Gray)
{
this.BackColor = Color.Green;
}
else
{
this.BackColor = Color.Gray;
}
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2(new BackClo(changc));
f2.ShowDialog();
}
}
}
form2代码
namespace WindowsApplication1
{
public partial class Form2 : Form
{
BackClo at;
public Form2(BackClo bc)
{
InitializeComponent();
at = bc;
}
private void button1_Click(object sender, EventArgs e)
{
at();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询