| | |
How do I suspend control on one form until data is entered on another?
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 63
Reputation:
Solved Threads: 4
Hello,
I have an application where (and this is probably not how its done but something I'd like to do) the user clicks a button which brings up another form with 2 text boxes. The user enters text, and then clicks ok. The user entered text is then passed to a constructor to an object instantiated in form1. I noticed that control flow during form1's click event falls to the next line after form 2 is shown. Can I "suspend" control flow on form1, passing focus to form2 until the ok click event occurs on form2 so I can use its data to instantiate my constructor? In short, what I'm trying to do is this:
I tried writing a delegate for this, but I don't declare an instance of form1 on form2 so I don't have access to its methods. I could just put the text fields on form1 but that would clutter up other functionality and overall display of the form. No matter what I pass to form 2, control immediately falls back to the next line in form1. I created a boolean value in the struct, set it to false in form1 and true in form 2, placed the constructor after the while loop once the value fell to true, but that seems inelegant and it crashes the debuger with all of the context switching (this leads me to infer that form2 is not a thread but a forked process which therefore has its own process space. Which is rather daunting if so.)
I realize there are other ways to have written this, perhaps passing in a reference to the struct is a bad idea, but the problem still remains. I need data from form2 to be instantiated on form1 during form2's click event.
I vaguely remember from a VB6 class years ago that you can swap focus for forms and events but I am now more curious as to the hows and whys of form application behavior so I don't write a ticking time bomb just trying to instantiate a constructor.
Thanks a lot in advance!
I have an application where (and this is probably not how its done but something I'd like to do) the user clicks a button which brings up another form with 2 text boxes. The user enters text, and then clicks ok. The user entered text is then passed to a constructor to an object instantiated in form1. I noticed that control flow during form1's click event falls to the next line after form 2 is shown. Can I "suspend" control flow on form1, passing focus to form2 until the ok click event occurs on form2 so I can use its data to instantiate my constructor? In short, what I'm trying to do is this:
C# Syntax (Toggle Plain Text)
public class myClass { public myClass(int a, int b); //...constructor, and class methods, members, accessors etc. } public struct constructordata { public int int_a; public int int_b; } public partial class form1 : Form { public Form1() { InitializeComponent(); } private void Its_Ok_button(object sender, EventArgs e) { constructordata c_data = new constructordata(); //Passing in constructordata to form 2. Form2 form2 = new Form2(ref c_data); form2.Show(); //Here I want to wait until the data has been assigned in form 2. myClass class = new myClass(c_data.int_a, c_data.int_b); } . . . public partial class Form2 : Form { public Form2(ref constructordata c_data) { InitializeComponent; } private void data_ok_Click(object sender, EventArgs e) { c_data.int_a = textBox1.Text.ToInt16(); c_data.int_b = textBox2.Text.ToInt16(); // So here is where I want focus to return back to form1. }
I tried writing a delegate for this, but I don't declare an instance of form1 on form2 so I don't have access to its methods. I could just put the text fields on form1 but that would clutter up other functionality and overall display of the form. No matter what I pass to form 2, control immediately falls back to the next line in form1. I created a boolean value in the struct, set it to false in form1 and true in form 2, placed the constructor after the while loop once the value fell to true, but that seems inelegant and it crashes the debuger with all of the context switching (this leads me to infer that form2 is not a thread but a forked process which therefore has its own process space. Which is rather daunting if so.)
I realize there are other ways to have written this, perhaps passing in a reference to the struct is a bad idea, but the problem still remains. I need data from form2 to be instantiated on form1 during form2's click event.
I vaguely remember from a VB6 class years ago that you can swap focus for forms and events but I am now more curious as to the hows and whys of form application behavior so I don't write a ticking time bomb just trying to instantiate a constructor.
Thanks a lot in advance!
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
whoaaa, just use a dialog
and i would use that ref, just use, properties in the second form
and i would use that ref, just use, properties in the second form
C# Syntax (Toggle Plain Text)
Form2 form2 = new Form2(); form2.ShowDialog(); if(form2.DialogResult == DialogResult.OK) { myClass class = new myClass(form2.IntA, form2.IntB); }
Last edited by dickersonka; Nov 10th, 2008 at 4:52 pm.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
•
•
Join Date: Aug 2008
Posts: 1,160
Reputation:
Solved Threads: 137
i guess just to be thorough, he is what form2 could be
C# Syntax (Toggle Plain Text)
public class Form2 : Form { //all the other code private int int_a; public int IntA { get { return int_a; } } }
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Other Threads in the C# Forum
- Previous Thread: error on sqlserver database connection please rectify that
- Next Thread: I'm new & I need help
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client combobox connection console control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment developer development draganddrop drawing editing encryption enum event excel file form format forms function gdi+ hospitalmanagementinformationsystem httpwebrequest image imageprocessing index input install java label list listbox mandelbrot math mouseclick mysql operator oracle path photoshop picturebox pixelinversion post priviallages. programming radians regex remote remoting richtextbox rows serialization server sleep socket sql statistics stream string table temperature text textbox thread time timer txt update uploadatextfile usercontrol validation visualstudio webbrowser windows windowsformsapplication winforms wpf xml






