1、在已经选择了comobox中的一个选项后,textbox中会显示字符串,但是当将comobox中的
的东西给删掉后,textbox中的字符还存在
2、在写的比较大点的程序后,当comobox中为空时,会出现这样的情况:
程序会一直记着combox为空,即使你将comobox中选到有字符的时候,但接下来
全执行的是comobox为空时的代码,
为什么呢????????
怎么解决???
的东西给删掉后,textbox中的字符还存在
2、在写的比较大点的程序后,当comobox中为空时,会出现这样的情况:
程序会一直记着combox为空,即使你将comobox中选到有字符的时候,但接下来
全执行的是comobox为空时的代码,
为什么呢????????
怎么解决???
全执行的是comobox为空时的代码
我想你说的“接下来”执行的那段代码,在comobox没值的时候就已经执行了吧你需求没说清楚 我只能这么回答了
private void comboBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Text = comboBox1.Text;
}
试试
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 帐号找回器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int erroTimes = 0;
private void button1_Click(object sender, EventArgs e)
{
string 姓名 = txt姓名.Text,
生日 = txt生日.Text;
string 密码 = txt密码.Text;
string yonghu = cb用户名.SelectedText;
string 用户名; int 序号 = cb用户名.SelectedIndex;
textBox1.Visible = false;
if (姓名 == "")
{
MessageBox.Show("您输入的姓名为空,请在次输入!"); return;
}
else if (姓名 != "hello")
{
textBox1.Visible = true;
textBox1.Text = Convert.ToString("提示信息"); return;
}
else if (生日 == "")
{ MessageBox.Show("您输入的生日为空,请重新输入!"); return; }
else if (密码 == "")
{ MessageBox.Show("您输入的密码为空,请在次输入"); return; }
else if (cb用户名.SelectedText == "")//当comobox为空时,会出现异常
{ MessageBox.Show("用户名选择为空,请重新输入!"); return; }
else if (cb用户名.SelectedText!=""&&生日 == "20120506" && 密码 == "88888888")
{
pictureBox1.Visible = true;
switch (序号)
{
case 0: 用户名 = "helloworld";
break;
case 1: 用户名 = "helloworld1";
break;
case 2: 用户名 = "[email protected]";
break;
case 3: 用户名 = "淡淡的";
break;
case 4: 用户名 = "hello2";
break;
case 5: 用户名 = "hello3";
break;
case 6: 用户名 = "hello4";
break;
default: throw new Exception("无法预知的错误");
} txt用户名.Text = 用户名;
txt用户名.Visible = true;
}
else
{
erroTimes++;
if (erroTimes >= 3)
{
MessageBox.Show("您输入错误的次数太多,程序即将退出!");
Application.Exit();
}
MessageBox.Show(string.Format("您输入的生日或密码错误,您还有{0}次机会!",
3 - erroTimes)); return;
} }
}
}
代码:
我想问的:按F5执行后,输入姓名,密码和生日后,但是没有选择combox,点击按钮,会提示未选择,
然后再在combox中选择一个,点击按钮,但照样提示没有combox中没选择,为什么怎么改???
private void comboBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Text = comboBox1.Text;
aa = comboBoX1.Text;
} private void button1_Click(object sender, EventArgs e)
{
textBox1.text = aa;
}你用一个字符串保存comboBox1修改后的值,然后在单击确定就是你新给的值了!