WinForms - Show dialog and still use the calling form - c#

I have a requirement where the user wants to be able to click a button to show a dialog with some information. They want the ability to move the dialog off of the form and put focus back on the calling form and make changes to the calling form with the dialog still open.
It is basically a map on the main form and the dialog is a map legend.
Is this possible? How would I accomplish this task? It seems like I would need to do something with a panel like how Visual Studio does this with their dockable panels.

Call the Show method instead of ShowDialog.
This method is a non-blocking call (unlike ShowDialog, it will return immediately, not after the new form closes) and will not show the form modally.
You'll probably want to pass the parent form as the parameter so that it will show as a child form.

You can show the dialog in non-modal way.
Like this:
formLegend.Show();

Insead of calling legendForm.ShowDialog(), just use legendForm.Show(). It will display the legend form without restricting the map's usage.

Related

Multi form Projects in c# - Displaying multiple windows

My main form is this
Now my problem occurs when I click Add -> Student, which is meant to bring up a new window that, instead it does this
So as you can see it opens the new form inside the same window. It didn't use to do this, then I made the main form an MdiContainer and set it as the MdiParent of the second form.
Is there a property I can change to make this new form pop up in a new window? Becuase I need to leave the MdiContainer property as True so that I can take data from Form2 and use it in Form1
Please let me know any other information you may need to help me fix this issue, as I'm not sure what caused it so I don't know what to change in order to fix it or even where I'm meant to be looking
you need to hide form enroll
when you open add window add.show()
you need to hide enroll form enroll.hide()

C# - Use form instead of messagebox

I am working on an application for work and I need a customized messagebox to appear. I have created a simple form called Alert.cs that I have styled the way I want and added one button with a click method of this.Close(). now I want it to behave exactly like a standard messagebox.show(). I have the form showing but when I use the standard messagebox.show("text of alert") it waits to continue operation until the user click 'OK', this is what I want the form to do.
Use Form.ShowDialog();. This allows the form to act the same way as a MessageBox in the sense that it retains focus until closed.
You will need to implement a static method for your Alert class if you want the exact MessageBox-like behaviour.
public static DialogResult Show(string text)
{
Alert form = new Alert(text);
return form.ShowDialog();
}
Now you can use the form by calling:
Alert.Show("my message");
You can use a modal windows form. Something like
Form frm = new Form();
frm.ShowDialog(this);
See Form.ShowDialog Method
Shows the form as a modal dialog box
with the currently active window set
as its owner.
Displaying Modal and Modeless Windows Forms
You don't write how you currently display your Alert Form, but calling
alert.ShowDialog();
instead of alert.Show() should do the trick.
The ShowDialog that takes an owner is an even better alternative:
alert.ShowDialog(owner);

How do a make one form stay on top of another?

I have found the Form.TopMost property but it puts the form on top of everything, including stuff that isn't part of my app. I've got a suspicion that I'm missing something obvious here. (Is Form the proper bases class for a non modal dialog box?)
Use the Form.Owner property of your dialog form and set it to the main Form.
Read more here
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner.aspx
The Owned form will never be displayed behind the Owner Form.
It is very simple; You just have to pass the owner when you call the Show() method
YourForm.Show(parentForm);
You can specify parent-child relationships between windows by supplying the parent Form as parameter to the ShowDialog() method called on the child Form. The child window will then stay on top of the parent and also minimize and restore along with the parent.
If i understand you correctly your opening a form from your application, and you want your new form to be on top of the old one.
To do this you can use ShowDialog() and StartPosition
SomeForm MyNewForm = new SomeForm();
MyNewForm.ShowDialog();
this will make that form stay on top of the orignal one, and you can also use
MyNewForm .StartPosition = FormStartPosition.CenterParent;
To control where that new form shows on the screen.

Windows forms: ShowDialog - dialog doesn't show up

I am running an external process from an outlook plugin - and it doesn't show the dialog. I am using ShowDialog without parameters.
Any ideas how to show the dialog ?
The process doesn't have any form - i just want to show a dialog with some selections. If I call "MessageBox.Show" before, the dialog is shown - otherwise not.
I guess it is something like the answer of Peterchen in this thread: Form.ShowDialog() or Form.ShowDialog(this)?
BTW I don't have any owner, because this process doesn't have any "main window".
Any ideas ?
I think you would need a parent window for modal windows to work. After all, the only difference from Show() is that the child window blocks the parent. You can always create a hidden dummy window and use it as a main window but why not just use .Show() since it works ?

How do you make a non-modal topmost dialog that is only topmost in regards to the parent form in WinForms?

Thinking about this for an About dialog but I'm sure it's applicable in other places (say a find box)
Sorry if this is a dupe, but I couldn't find this or how to articulate the last part about it only being on top of the parent. How do you make a form that is always on top of the parent form, but is non-modal, but doesn't cover up other apps?
Try this to open your dialog:
FindDialog fd = new FindDialog();
fd.Show(this);
The key is to assign dialog's owner.
Not sure exactly what you mean; Form.ShowDialog is only modal with respect to the parent, not the application, unless the application is single threaded.
For example, I made an app to test this which was organized like the following:
mainform:
2 buttons, each of which begins a thread that creates a frmDialog1 and calls ShowDialog
frmDialog1:
single button which creates a frmDialog2 and calls ShowDialog on it.
frmDialog2:
does nothing (ie. blank)
when they were all running I could access/drag mainform. I could also do the same with frmDialog1 (both versions) only if I hadn't clicked the button that shows dialog 2.

Categories

Resources