1 图像 pictureBox
首先在属性里设置visible设置为隐藏
private void button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text.Substring(6,4); //取子字符串 身份证的年
int age;
if (!int.TryParse(str,out age))
{
MessageBox.Show("身份证格式错误!");
return;
}
if (DateTime.Now.Year - age >= 18) //就简单点写了
{
pictureBox1.Visible = true; //设置visual属性
// pictureBox1.Show(); //调用方法也可以
}
else
{
MessageBox.Show("未满18!");
}
}
2 滚动文本框
private void button1_Click(object sender, EventArgs e)
{
string str = textBox.Text;
char first = str[0];
string 剩下 = str.Substring(1);
textBox.Text = 剩下 + first;
}
private void button2_Click(object sender, EventArgs e)
{
string str = textBox.Text;
char last = str[str.Length-1];
string 剩下 = str.Substring(0,str.Length-1);
textBox.Text = last + 剩下;
}
}
3 文本框
当设置属性PasswordChar时 可以设置成密码文本框
设置multiLine属性时,可以变成多行文本框
点击追加当前时间
private void button1_Click(object sender, EventArgs e)
{
textBox4.AppendText(DateTime.Now.ToString() + "\n"); //附加
//较差的方法是 textBox4 += DateTime.Now.ToString; //这种方法要读取text的值再附加回去 在数据量大的时候非常慢
}