Outlook add-in open dialogs

  • Thread starter Thread starter J E Jensen
  • Start date Start date
J

J E Jensen

Hello NG

On a property page that i have added to the outlook options form, i have a
button. And when the user clicks that button i want the FolderBrowserDialog
to open.

My code:
using (FolderBrowserDialog fbd = new FolderBrowserDialog())

{

fbd.Description = "Select folder";

fbd.SelectedPath = DefaultFolder;

if (fbd.ShowDialog() == DialogResult.OK)

strReturn = fbd.SelectedPath;

}

It do not shows on the screen, if i pause the code it stops at the
If(fbd.ShowDialog() == DialogResult.OK) line. I think that Outlook can't
open a modal dialog from the property pages.

Is there another way to do that.

Kind regards
Johnny Jensen
 
Sure you can open a modal dialog on top of a property page, I do it all the
time.

You just need to pass along the window handle of the window you want the
dialog to be on top of as the owner of your dialog. Get the hWnd of your
property page and pass that as the hWnd of the owner of the dialog.

You can also set the TopMost property of your dialog.
 
Hello Ken

Thanks for helping.
The dialog i want to display i the System.Windows.Forms.FolderBrowserDialog
this dialog allow me to pass a IWin32Window as the owner, so I stubbled over
a snipet to help me.

The wrapper:
public class WindowWrapper : System.Windows.Forms.IWin32Window

{

public WindowWrapper(IntPtr handle)

{

_Handle = handle;

}

private IntPtr _Handle;

public IntPtr Handle

{

get { return _Handle; }

}

}



I'll get the Outlook's handle by:
System.Diagnostics.Process[] proc =
System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

if (proc.Length > 0)

{

IntPtr hwnd = proc[0].MainWindowHandle;

}

The create a new instance of the WindowWrapper with the hwnd in the
construstor.

Then i use the FolderBrowserDialog.ShowDialog(new WindowWrapper(hwnd))
but the dialog never shows.

Kind regards
Johnny Jensen
 
My guess is that will place your dialog behind the property page but in
front of the main Outlook window, in other words invisible. I'd use the hWnd
for the property page form or usercontrol you are using rather than the hWnd
of the main Outlook window.
 
Back
Top