Is it possible to set ShowDialog () so that it is not the topmost?

Is it possible to set ShowDialog () so that it is not the topmost? I looked through all the questions related to him, and none of them corresponded to my situation.

What I am doing is opening a new WinForm from the column column of the datagridview button. This new form displays information from several SQLite tables and allows the user to add information to the row that the button was clicked on.

I open WinForm using the following code. I use the ShowDialog () method, so I can find out if the user saves the information in the form or cancels it.

Pay_Bill_Window paywindow = new Pay_Bill_Window(getClickedRowID); if (paywindow.ShowDialog() == DialogResult.OK) { FillPendingPaymentDataGrid(dbAccess.GetPendingBills()); } 

I do this, so I can tell if I need to reload the information in a datagridview.

The information that the user can fill in the window is obtained from other sources, such as a web browser, so having a form above all applications is not ideal.

Is there a way that I can stop the window from being on top of all applications (the top one in my series of windows is ok), or is there a way to tell which button the user clicks on another form (mainly using paywindow.Show() and watching another type of return)?

Thanks for any help!

+1
source share
5 answers

use something like this: form1:

  private void button1_Click(object sender, EventArgs e) { Form2 frm = new Form2(); frm.Show(); frm.FormIsClosing += frm_FormIsClosing; } void frm_FormIsClosing(object sender, DialogResult rsl) { if (rsl == System.Windows.Forms.DialogResult.Yes) MessageBox.Show("We got it"); } 

form2:

  public delegate void IsClosing(object sender, DialogResult rsl); public event IsClosing FormIsClosing; private void Form2_FormClosed(object sender, FormClosedEventArgs e) { FormIsClosing(this, System.Windows.Forms.DialogResult.Yes); } 

then you close form2, FormIsClosing lights, and you can catch it from1;)

+1
source

By default, the form should not be TopMost with the value "for all applications". If you see this behavior, this is likely because the property was set in the designer. Either disable the property in the constructor, or try the following.

 using ( Form form = CreateMyForm() ) { form.TopMost = false; form.ShowDialog(parent); ... } 
+1
source

I did not find a way for the form to not be the largest when it is shown using ShowDialog() (this shows the form as modal, and I do not know how to redefine it).

However, I found a way to watch the second form when it was shown using Show() , watching the form.Disposed event at fooobar.com/questions/1321897 / ....

From Ian :

 Form2 form2 = null; void button_click(object sender, EventArgs e) { if(form2 == null) { form2 = new Form2(); form2.Disposed += new EventHandler(f_Disposed); form2.Show(); } } void f_Disposed(object sender, EventArgs e) { form2 = null; } 

As far as I can tell, this does not allow me to understand why the form is closed (for example, using DialogResult ), so the event fires every time the form closes, which is good for my situation.

0
source
 paywindow.ShowDialog(this) 

must work. an additional parameter indicates how the parent element is located and will make it a layer on top of the parent, but not the top one. The top one means that the window will stand on your desktop, even if you activate another window. This is not the default behavior for ShowDialog. As JaredPar mentioned, set your form / window to TopMost = false so that it is true.

0
source
 paywindow.ShowDialog(this) 
-1
source

All Articles