locked
FileDialog StartPosition RRS feed

  • Question

  • I'm using .NET 2.0.  I instantiate OpenFileDialog and SaveFileDialog objects under several different forms.  I show them using .ShowDialog(form) for the owning form.

     

    My problem is that the very first instantiation of either of these FileDialogs seems to set a permanent property so that future instances even owned by different forms will still open in the same position as the first, for the duration of the Application.

     

    Is there some way to set the StartPosition or otherwise deterministically set the location of a FileDialog?

    Tuesday, February 5, 2008 4:57 PM

Answers

  • I don`t think that is possible from the calling thread as OpenFileDialog is sealed and does not offer any property or method that will allow you to do this. So I think you would have to design your own OpenFileDialog or call the following APIs from another thread:

     

    Code Snippet

    [DllImport("user32.dll")]

    public static extern bool MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, bool repaint);

    [DllImport("user32.dll")]

    public static extern int FindWindow(string ClassName, string WindowName);

     

     

    Regards,

    Fábio

    Wednesday, February 6, 2008 12:28 PM
  • please check this out then: codeguru: Customizing OpenFileDialog in .NET

     dbooksta wrote:
    No, I'm referring to the physical screen location of the Dialog box.

     

    Wednesday, February 6, 2008 2:31 PM

All replies

  • set InitialDirectory
    Tuesday, February 5, 2008 5:36 PM
  • No, I'm referring to the physical screen location of the Dialog box.

     

    Tuesday, February 5, 2008 10:32 PM
  • I don`t think that is possible from the calling thread as OpenFileDialog is sealed and does not offer any property or method that will allow you to do this. So I think you would have to design your own OpenFileDialog or call the following APIs from another thread:

     

    Code Snippet

    [DllImport("user32.dll")]

    public static extern bool MoveWindow(int hwnd, int x, int y, int nWidth, int nHeight, bool repaint);

    [DllImport("user32.dll")]

    public static extern int FindWindow(string ClassName, string WindowName);

     

     

    Regards,

    Fábio

    Wednesday, February 6, 2008 12:28 PM
  • please check this out then: codeguru: Customizing OpenFileDialog in .NET

     dbooksta wrote:
    No, I'm referring to the physical screen location of the Dialog box.

     

    Wednesday, February 6, 2008 2:31 PM