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 ?
Related
Let's say I have some threads running there.
They must perform some actions only if no modal forms shown over main form.
I don't want to add hack checks like setting some flag before opening some modal form. Is there any generic way?
We use this hack:
if (this.Visible && !this.CanFocus)
{
//another modal window is opened
}
But you should know, that modal window "blocks" main form execution. And you can check this only in some cases, like repainting.
I have in my application the standard UI-Thread and additional a second UI-Thread. Now, I create and show a Window in the second UI-Thread. After this, I should create and show a Dialog in the standard UI-Thread but it should be modal to the window, which was created and shown in the second UI-Thread. The reason is, that I have to create this Dialog in the standard UI-Thread, that this Dialog uses a Control which is not ThreadSafe.
You should just be able to set Owner property of the window:
newWindow.Owner = parentWindowFromOtherThread;
I have a form which instances a new form that I've already created using
statuswindow statwin = new statuswindow();
statwin.ShowDialog();
return statwin;
This code is in a function. The problem is when I run the function in other code the next line of code doesn't run until the newly instanced window is closed by the user, I'm guessing this is the side-effect of using ShowDialog(), is there a way to have it use the same behaver (being topmost, not being to select the other main window) while still letting the main form's code run?
Update: Although Show(); will work, I need to be able to make the window like a dialog by having it always on top of the other window and it always being the active selected window.
The ShowDialog method of showing a window shows it as a dialog, which is a blocking mechanism within C#/.net. If you want to simply display the window and not cause the running code to block until it is closed, you can use the window.Show() function.
In your code:
startwin.Show();
This will cause the startwin form to become visable to the user, and will fire the startwin.VisibleChanged event as well as the startwin.Load event to fire.
To make the new window always on top, you could set the Topmost window flag in the form properties.
To make the window run in a separate thread, first spawn the thread, then create the window from that thread.
There are also "application modal" and "system modal" Win32 window flags, but I don't know if those are exposed to WinForms or not -- go have a look on the form properties!
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.
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.