在C# winform开发中,运行中停止的指令是什么

在C# winform开发中 在运行的时候,我需要在中途停止(比如就是键盘输入不符合我设计要求时),不执行后边的程序,我应该加个什么代码?

第1个回答  2013-08-11
可以使用if判断键盘输入字符,使用return命令中止程序运行。代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox1_TextChanged(object sender, EventArgs e)
{
string nowString = this.textBox1.Text[this.textBox1.Text.Length - 1].ToString();
if (nowString == this.textBox2.Text)
{
this.Dispose();
}
}
}
}
结果 输入g则中止运行
第2个回答  2013-08-11
你可以使用return语句实现。例如:在textbox中输入了一个字符,若此字符不为数字则停止操作,返回。ch=Textbox.text;if(!char.IsDigit(ch)){return;}//若是则进行相关的操作。。。。
第3个回答  2013-08-11
e.cancle=true
第4个回答  2013-08-11
if(){ return;}
相似回答