5

How can I create a Settings dialog for a Word Addin.

I have already creating a Windows Form and I'm calling 'form.Show()`. But It's creating a new Window.

How can I pass the owner by form.ShowDialog(owner)?

I've solve my question creating a Helper for open the Dialog, but I don't know if is the best way

public static DialogResult ShowDialog(Form dialog)
{
    NativeWindow mainWindow = new NativeWindow();
    mainWindow.AssignHandle(Process.GetCurrentProcess().MainWindowHandle);
    DialogResult dialogResult = dialog.ShowDialog(mainWindow);
    mainWindow.ReleaseHandle();
    return dialogResult;
}
4

1 回答 1

7

I solve the question creating the code:

public static DialogResult ShowDialog(Form dialog)
{
    NativeWindow mainWindow = new NativeWindow();
    mainWindow.AssignHandle(Process.GetCurrentProcess().MainWindowHandle);
    DialogResult dialogResult = dialog.ShowDialog(mainWindow);
    mainWindow.ReleaseHandle();
    return dialogResult;
}
于 2012-09-24T17:04:41.780 回答