VB.NET - Can't I "disable" the Startup form when it open a new form?

626 views Asked by At

I have learn today that using the method .ShowDialog() to open a new form, it will not allow to user (until the new form be closed) to "use" this form but I tried do it and this form still can be "usable".

The form that open the new one is my startup object. What did I do wrong?

  • Start-up object: Form

  • Form to be open: AddQuestion


At Form I have:

Private Sub ButtonX5_Click(sender As Object, e As EventArgs) Handles ButtonX5.Click
        AddQuestion.ShowDialog(Me)

    End Sub
2

There are 2 answers

0
AudioBubble On

Try this:

Dim aqForm = New AddQuestion()
aqForm.ShowDialog(Me)
0
Haji On

For example we have Form1 and we want to call Form2. we may write like this in Form1

private void button1_Click(object s, EventArgs e) 
{ 
Form2 f=new Form2(); 
f.Show(); 

} 

we can also write f.ShowDialog();

The difference:

Show method does not make the target form (Form2 in this case) as a modal dialog box. ShowDialog() will make Form2() as a modal dialog box. So, when we use ShowDialog() method, we cannot click anywhere on Form1 unless we close the instance of Form2. In case of Show(), we can click on Form1 even when Form2 is open.