我定义了一个窗体StartForm,然后在里面加入了一个button按钮,现在想在主程序中象对话框一样调用它,即:
StartForm sf = new StartForm(this);
int dlgResult = sf.ShowDialog();
if(dlgResult)==OK)
{
..........
}
else
{
.............
}
请问该怎么让我自定义的窗体在按下确定的时候返回值到主窗口呢?

解决方案 »

  1.   

    把确定button的DialogResulr属性设为OK
      

  2.   

    StartForm sf = new StartForm(this);
                if (sf.ShowDialog() == DialogResult.OK)
                {
                    Console.WriteLine("点击了确定返回");
                }StartForm的确定按钮代码:
    --------------
    private void button1_Click(object sender, EventArgs e)
            {
                this.DialogResult = DialogResult.OK;
            }
      

  3.   

    if(dlgResult)==OK)
    {
    this.hide()
    yourMainWindow mwindow = new yourMainWindow();
    mwindow.show()
    }
      

  4.   

    this.Hide();//隐藏本界面
    mainControl mainCon=new mainControl();
    mainCon.Show();//跳到主界面
      

  5.   

    在自定义的窗体的那个button的事件响应函数中,加入this.close()。