获取TextBox内容
string name = this.txtName.Text;
string remark = this.txtRemark.Text;
if (name.Contains(" ")) {
MessageBox.Show("用户名不能包含空格!","内容非法");
return;
}
if (name.Length < 6) {
MessageBox.Show("用户名不能少于6个字符!","内容非法");
return;
}
string info = name + "\r\n" + pwd + "\r\n" + remark;
设置 TextBox内容
this.txtFirst.Text = info;
MessageBox显示
MessageBox.Show("密码不能少于6个字符!", "内容非法");
DialogResult dr = MessageBox.Show("你确实要取消注册吗?","确认取消",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
Application.Exit();
}
else {
this.txtName.Text = "";
this.txtPwd.Text = "";
this.txtRemark.Text = "";
}
显示窗口面板
frmShow frmshow = new frmShow();
frmshow.Show();
获得listBox的所有内容
public string _name;
int i = listBox1.SelectedIndex;
listBox1.Items[i] = f2._name;
listBox2.Items.Add(name);
string name = this.listBox1.Text;
foreach (string str in listBox2.Items)
{
if (str == name)
{
n++;
}
}
类的构造函数
namespace CommunicationForm
{
public partial class frmSecond : Form
{
private frmFirst ff = null;
public frmSecond()
{
InitializeComponent();
}
public frmSecond(frmFirst frmfirst)
{
InitializeComponent();
this.ff = frmfirst;
}
public void SetInfo(string info) {
this.txtSecond.Text = info ;
}
private void btnChange_Click(object sender, EventArgs e)
{
ff.SetInfo(this.txtSecond.Text);
}
}
}