代码如下:namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
            ck.S();
        }
    }    public  class ck
    {
        static public void S()
        {
            Form1 f1 = new Form1();
            int K = Convert.ToInt16(f1.textBox1.Text) + 1;
            f1.textBox1.Text = K.ToString();        }               } 
}
每次窗体初始化后 textbox1.text 都是空值,运算报错。

解决方案 »

  1.   

    这段代码起什么作用没看懂 你将S 函数改成static public void S(ref From f1)
     去掉 S 函数中  Form1 f1 = new Form1();
     在 Convert.ToInt16(f1.textBox1.Text) 执行前加一个 判断 if( f1.textBox1.Text !="")
     如何?
      

  2.   

     int K = Convert.ToInt16(f1.textBox1.Text) + 1;
    =〉
    int K = 1;
    try { K = Convert.ToInt16(f1.textBox1.Text) + 1; } catch { }
      

  3.   

    最主要的问题是ck.S函数中重新new Form1。按照1楼的方法改就行了
      

  4.   

    因为窗体实例化,在窗体上填写的值,都恢复了默认的设置,比如 TEXT里面我填写的是 2,实例化之后就变成了空值
      

  5.   

    private void button1_Click(object sender, EventArgs e)
            {
                ck.S(this);
            }==================
    static public void S(Form f1)
            {
               try
               {
                int K = Convert.ToInt16(f1.textBox1.Text) + 1;
                f1.textBox1.Text = K.ToString();
               }catch{}        }