Values between windows forms in C# .NET

浪尽此生 提交于 2019-12-20 04:18:13

问题


I have two forms, in the main one a have a crystalreportviewer and in the other one the user introduces the ID of the user he wants to be on the report. The problem I want the user to introduce the ID before the report loads the information, so when the user clicks the CreateReport button just before the report loads the info, I created a new form to introduce the ID, the problem is that instructions continue to execute even though the new window is open. I know is a problem of logic instead of programmin maybe you can help me =). I made a constructor in the form so the values can be passed.

Here is the code of the button:

    private void usuariosToolStripMenuItem_Click(object sender, EventArgs e)
    {

            RPE formRPE = new RPE(); //NEW FORM CREATED
            frmRPE.Show();//RPE FORM CALLED
            this.Hide();

        //BUT IT GOES ON

            ReportDocument guantesRpt = new reporteGuantes();

            DataTable datatableGuantes = reporteguantes.obtenerTabla();
            guantesRpt.SetDataSource(datatableGuantes);





            rptViewerGuantes.ReportSource = guantesRpt;
            //  Usuariorpt.SetParameterValue("RPE", RPE);



    }

回答1:


ShowDialog(...)




回答2:


Form.show() is used when you want a modeless form. So when you call show it sets up the form to run on its on and then continues to execute the code where you called the show.

Since you want to block the user input and code execution until they deal with your report ID form, you want a modal form. As such look at Form.ShowDialog() which will block execution until the form is dismissed and will then give you a DialogResult where you can retreive the result from the user and then get any form specific information from the form instance. Here is the msdn for ShowDialog()



来源:https://stackoverflow.com/questions/993853/values-between-windows-forms-in-c-sharp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!