有一个文本框a.text,3个Label的Text值分别为我, 你, 他。现在要在文本框中输入一段公式,例如:我+你*他,或者:我/他 等,但是输入的必须是这3个Label的Text值,后台验证控件怎么验证输入的正确
解决方案 »
- Application.DoEvent()再一次求解!!!!
- toolStripDropDownButton 动态创建多层菜单后,如何获取用户选择
- C#生成文字水印或者图片水印时的问题
- 把查询结果以CSV形式,用系统默认的文本编辑器显示给用户 急急急急急急急急
- 新手提问,我用VISUAL C#,生成的EXE文件无法运行。我已经安装了.net framwork
- 高分求教:最高效或最易懂或最巧妙或兼而有之的-文字竖排算法
- 编写计算器是,按Button键上的1和2时,如何在Textbox1上显示12啊!!
- 写消灭QQ的服务!
- 重装系统后,如何使用原有的msdn2005?
- 如何控制一条线程监听一个串口?
- 问个重绘的问题
- C# DataGridView单元格中含有超链接的问题,谢谢
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
bool result = true;
byte[] t1 = Encoding.ASCII.GetBytes(textBox1.Text);
byte[] t2 = Encoding.ASCII.GetBytes(textBox2.Text);
byte[] t3 = Encoding.ASCII.GetBytes(textBox3.Text); foreach (byte b in t1)
{
if (e.KeyChar == Encoding.Default.GetChars(t1)[0])
result = false;
} foreach (byte b in t2)
{
if (e.KeyChar == Encoding.Default.GetChars(t2)[0])
result = false;
} foreach (byte b in t3)
{
if (e.KeyChar == Encoding.Default.GetChars(t3)[0])
result = false;
} e.Handled = result;
}
{
bool result = true;
string str = textBox1.Text + textBox2.Text + textBox3.Text;
byte[] t = Encoding.ASCII.GetBytes(str); foreach (byte b in t)
{
if (e.KeyChar == b)
result = false;
} e.Handled = result;
}
这截取的方法比较愚蠢,你可以改用前台正则验证protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text + textBox2.Text + textBox3.Text;
int keycharvalue = Encoding.ASCII.GetBytes(TextBox1.Text.Substring(TextBox1.Text.Length - 1,1))[0];
if (EnterJudgmentMethod(keycharvalue, str))
TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1);
}
/// <summary>
/// 控制键盘输入方法
/// </summary>
/// <param name="KeyCharValue">键盘输入的ASCII值——e.KeyChar值</param>
/// <param name="str">输入的字符集合</param>
/// <returns></returns>
public static bool EnterJudgmentMethod(int KeyCharValue, string str)
{
bool result = true;
byte[] t = Encoding.ASCII.GetBytes(str); foreach (byte b in t)
{
if (KeyCharValue == b)
result = false;
}
return result;
}
你要是每次输入的字符串不是很长,你就以此判断一下呗
你可以写个函数 public static bool HasTheWorld(string strTest)
{
bool hasWorldFlag = false;
string strBase = "+—*/你我他";
if (strBase.Contains(strTest))
{
hasWorldFlag = true;
}
return hasWorldFlag;
}其中strTest为你需要判断字符串中的每个字符,你可以循环去判断,但发现有一个字符不在你规定的字符中,判断结束