关于if() {} else{}

maladola 2004-03-31 03:52:58
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text=="")
{
this.Close(); //怎样写才能彻底关闭窗体
}
else
{
MessageBox.Show("Can't be Closed!");
}
MessageBox.Show("Why and i style here!"); //程序为什么会运行这一句。
}
...全文
27 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dzliang21 2004-03-31
  • 打赏
  • 举报
回复
if(textBox1.Text =="")
{
this.Close();
Application.Exit();
return;
}
else
{
MessageBox.Show("Can't be Closed!");
}
MessageBox.Show("Why and i style here!");
chenghaofeng 2004-03-31
  • 打赏
  • 举报
回复
因为那个函数还没有执行完啊。
xjaifly 2004-03-31
  • 打赏
  • 举报
回复
你可以this.点出窗口.Close();
而且你textbox.text 获取什么你那里没有写啊!
所以它会运行到下面的。如果IF成立它不会往下走的1
hfwang009 2004-03-31
  • 打赏
  • 举报
回复
會出現的.即使把它換成application.Exit();還是會執行最後一句;之後他會回到Main()
Mitoko 2004-03-31
  • 打赏
  • 举报
回复
在this.Close();下面加一句return;
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text=="")
{
this.Close();
return;
}
else
{
MessageBox.Show("Can't be Closed!");
}
MessageBox.Show("Why and i style here!"); //程序为什么会运行这一句。
}
happyfish21cn 2004-03-31
  • 打赏
  • 举报
回复
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text=="")
{
this.Close(); //怎样写才能彻底关闭窗体
this.dispose();
return;
}
else
{
MessageBox.Show("Can't be Closed!");
return;
}
MessageBox.Show("Why and i style here!"); //程序为什么会运行这一句。
}
dzliang21 2004-03-31
  • 打赏
  • 举报
回复
在这里不能this.Close();

110,499

社区成员

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

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

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