show form
-
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
One shows a dialog (i.e. a modal window), the other shows a modeless window.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
Well, showdialog() causes the form to be show as a "dialog" (hence the name). That means that it will retain focus in your application: you will notice that you can't place the focus on the calling form while the dialog remains active/visible. Make sense?
-
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
In obj2.show you can move form everywhere but in another case it can move in the parent form area. I guess.. :|
-
In obj2.show you can move form everywhere but in another case it can move in the parent form area. I guess.. :|
freshonlineMax wrote:
n obj2.show you can move form everywhere but in another case it can move in the parent form area. I guess.. :|
You guess wrong. The second example just shows a dialog box. There's no constraint in where it can be moved - the constraint is in how you can interact with the hosting application. As it's modal, processing on the primary thread halts in the calling code until it is dismissed.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads
-
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
-
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
An additional addition to the previous good answers...
ShowDialog
returns a value of typeDialogResult
that enables you to determine the result of whatever that form was shown for - useful for custom message box type dialogs etc.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
What's the different between 2 code below? 1-Form2 obj1=new Form2(); obj1.show(); 2-Form2 obj2=new Form2(); obj2.showDialog(); :doh:
Yes Both are using for showing Form. But Firt one is used for showing form as a normal form. But Second One Is Used for Showing Form as a Dialog. You can not access Normally from Mouse or Keyboard. First Case shows Non Immediate Value Required. Second Shows Must Value Required. Best Regard
If you can think then I Can.
-
Well, showdialog() causes the form to be show as a "dialog" (hence the name). That means that it will retain focus in your application: you will notice that you can't place the focus on the calling form while the dialog remains active/visible. Make sense?
-
so you mean that with showdialog I can access the component in form2 like textbox? what can I do with dialog?
You need to make an accessor to expose the items you need from the form. Here is an example: I created a project with two forms. Form1 (parent/main) contains a textbox and a button. Form2 (dialog) has a textbox and two buttons (OK and Cancel). In the properties of the buttons, I set the "DialogResult" to "OK" and "Cancel" respectively, then in Form2's properties, set the AcceptButton to the OK button, and the CancelButton to the Cancel button. From there, the code is simple:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1\_Click(object sender, EventArgs e) { Form2 frm = new Form2(); if (frm.ShowDialog() == DialogResult.Cancel) return; //Cancel was chosen, so do nothing else textBox1.Text = frm.Value; } } public partial class Form2 : Form { public Form2() { InitializeComponent(); } /// <summary> /// Makes the value of the textbox accessible. /// </summary> public string Value { get { return textBox1.Text; } } }
-
You need to make an accessor to expose the items you need from the form. Here is an example: I created a project with two forms. Form1 (parent/main) contains a textbox and a button. Form2 (dialog) has a textbox and two buttons (OK and Cancel). In the properties of the buttons, I set the "DialogResult" to "OK" and "Cancel" respectively, then in Form2's properties, set the AcceptButton to the OK button, and the CancelButton to the Cancel button. From there, the code is simple:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1\_Click(object sender, EventArgs e) { Form2 frm = new Form2(); if (frm.ShowDialog() == DialogResult.Cancel) return; //Cancel was chosen, so do nothing else textBox1.Text = frm.Value; } } public partial class Form2 : Form { public Form2() { InitializeComponent(); } /// <summary> /// Makes the value of the textbox accessible. /// </summary> public string Value { get { return textBox1.Text; } } }