C# 一个登陆界面,选择不同的单选按钮,打开不同的窗口,,,但通过下列代码,都打开了同一个窗口???? 10
我要做一个登陆界面Form1,上面有三个单选按钮以及一个按钮,当选择RadioButton1并按button1时,Form2出现,而Form1关闭;当选择RadioBut...
我要做一个登陆界面Form1,上面有三个单选按钮以及一个按钮,当选择RadioButton1并按button1时,Form2出现,而Form1关闭;当选择RadioButton2并按button1时,Form3出现,而Form1关闭;以此类推。
我在Program.cs中将代码修改为:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (Form1 Form1 = new Form1())
{
switch (Form1.a)
{
case 0:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form3());
break;
case 1:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form2());
break;
case 2:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form4());
break;
default:
break;
}
}
Form1中的代码为:
public int a;
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
private void radioButton1_Click(object sender, EventArgs e)
{
a = 0;
}
private void radioButton2_Click(object sender, EventArgs e)
{
a = 1;
}
private void radioButton3_Click(object sender, EventArgs e)
{
a = 2;
} 展开
我在Program.cs中将代码修改为:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (Form1 Form1 = new Form1())
{
switch (Form1.a)
{
case 0:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form3());
break;
case 1:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form2());
break;
case 2:
if (Form1.ShowDialog() == DialogResult.OK)
Application.Run(new Form4());
break;
default:
break;
}
}
Form1中的代码为:
public int a;
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
private void radioButton1_Click(object sender, EventArgs e)
{
a = 0;
}
private void radioButton2_Click(object sender, EventArgs e)
{
a = 1;
}
private void radioButton3_Click(object sender, EventArgs e)
{
a = 2;
} 展开
3个回答
展开全部
就这样。。。
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.DialogResult = new Form1().ShowDialog();
}else if(radioButton2.Checked)
{
this.DialogResult = new Form2().ShowDialog();
}
else if (radioButton3.Checked)
{
this.DialogResult = new Form3().ShowDialog();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.DialogResult = new Form1().ShowDialog();
}else if(radioButton2.Checked)
{
this.DialogResult = new Form2().ShowDialog();
}
else if (radioButton3.Checked)
{
this.DialogResult = new Form3().ShowDialog();
}
}
更多追问追答
追问
谢谢你的回答,,,但我的意思是单击button1后,,,相应的Form2、3、4打开,而Form1消失。。。望您不吝赐教
追答
这样可以吗
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.Hide();
new Form1().ShowDialog();
}else if(radioButton2.Checked)
{
this.Hide();
new Form2().ShowDialog();
}
else if (radioButton3.Checked)
{
this.Hide();
new Form3().ShowDialog();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你想在哪个窗体中关闭程序,就在哪个窗体的formclosed事件里打上application.exit();这是主程序关闭的意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果要进程中没有该进程得用Application.Exit();这个代码,用close只是表面上关掉了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询