日期:2014-05-18  浏览次数:20889 次

请教高手--form间的值传递问题
在form1中有几个textbox,当点击form1中的删除按钮时,弹出form2对话框询问是否确认删除,当点击确认时form2关闭,并且form1中textbox的内容全部清空。
如何实现点击form2中的确认按钮时,form1中textbox内容清空?
请赐教!!!

------解决方案--------------------
C# code


            Form2 frm = new Form2();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.textBox1.Text = "";
            }

------解决方案--------------------
http://topic.csdn.net/u/20110407/19/c1068d69-7331-4d02-bc0b-f5ba7a5f8dd8.html
------解决方案--------------------
原来是根据TextBox的值清空数据库啊

C# code

DialogResult dr=MessageBox.Show("确实要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 if (dr==DialogResult.OK) 
{
 int i = cmd.ExecuteNonQuery();
 if(i>0)
{
 MessageBox.Show("删除成功");
 textBox11.Text=""; 
}
}

------解决方案--------------------
因为是MessageBoxButtons.YesNo
所以要写成if(dr==DialogResult.Yes)

------解决方案--------------------
C# code

public void button2_Click(object sender, EventArgs e)
{
    DialogResult dr=MessageBox.Show("确实要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    if (dr==DialogResult.OK)
    { 
      string connStr = "连接字符串";
      int result = 0;
      string sql = "delete from 投资方信息表 where 投资方名称 = @Name"
      string Name = this.TextBox1.Text.Trim();
      sqlparameter parm = new sqlparameter("Name",Name);
      using(OleDbConnection conn = new OleDbConnection(connStr);)
      {
         SqlCommand cmd = new SqlCommand();
         SqlCommand.Text = sql;
         SqlCommand.Parameters.Add(parm);
         SqlCommand.Connection = conn;
         SqlCommand.CommandType = CommandType.Text;
         result = Convert.ToInt32(cmd.ExecuteNonQuery());
      }
      if(result>1)
      {
          MessageBox.Show("删除成功");
          This.TextBox1.Clear();
      }
      else
      {
          MessageBox.Show("删除失败");
          This.TextBox1.Focus();
      }
    }
}

------解决方案--------------------
那你这样写

form2中这样写

 private textbox t;
 public 客户修改(textbox _t)
: this()
{
_t = t;
}

在你的事件中写t.text = "";
在父窗体下写如下代码
form2 f = new form2(你的textbox文本框);
f.show();

------解决方案--------------------
C# code

  [color=#FF0000]if(result>0)[/color]
      {
          MessageBox.Show("删除成功");
          This.TextBox1.Clear();
      }

------解决方案--------------------
上面几个都犯了一个错误
DialogResult dr=MessageBox.Show("确实要删除吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr==DialogResult.OK) //只有Yes和NO按钮,结果不可能是OK,应该是dr==DialogResult.Yes
{

}
------解决方案--------------------
(Application.OpenForms["form1"] as form1).textbox.Text=null;
//记得把textbox设置为Public