I want to set topmost my SaveFileDialog. But as you know there is no property. Is there any other way to set TopMost at SaveFileDialog?
How can I set topmost at the SaveFileDialog using C#?
Asked Answered
I guess you can make the calling Form topmost. –
Radborne
Why isn't your dialog already popping up to the top? –
Knitted
class ForegroundWindow : IWin32Window
{
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
static ForegroundWindow obj = null;
public static ForegroundWindow CurrentWindow {
get {
if (obj == null)
obj = new ForegroundWindow();
return obj;
}
}
public IntPtr Handle {
get { return GetForegroundWindow(); }
}
}
SaveFileDialog dlg=new SaveFileDialog();
dlg.ShowDialog(ForegroundWindow.CurrentWindow);
I can only think on a hack to do this. Make a new Form and set it TopMost. When you want to show the dialog, call from it:
Form1.cs
private void Form1_Load(object sender, EventArgs ev)
{
var f2 = new Form2() { TopMost = true, Visible = false };
var sv = new SaveFileDialog();
MouseDown += (s, e) =>
{
var result = f2.ShowSave(sv);
};
}
Form2.cs
public DialogResult ShowSave(SaveFileDialog saveFileDialog)
{
return saveFileDialog.ShowDialog(this);
}
If you want on the top of a specific form use
ShowDialog(form)
msdn.microsoft.com/en-us/library/9a55b9ds.aspx –
Cannelloni I already used ShowDialog(IWin32Window). :( Actually I use WPF windows. And I got a tab control in that window. All the tabs have an window, and each window has a single process. So I got a problem :( –
Sanborn
I solved this ref Bruno's answer :)
My code is this...
public System.Windows.Forms.DialogResult ShowSave(System.Windows.Forms.SaveFileDialog saveFileDialog)
{
System.Windows.Forms.DialogResult result = new System.Windows.Forms.DialogResult();
Window win = new Window();
win.ResizeMode = System.Windows.ResizeMode.NoResize;
win.WindowStyle = System.Windows.WindowStyle.None;
win.Topmost = true;
win.Visibility = System.Windows.Visibility.Hidden;
win.Owner = this.shell;
win.Content = saveFileDialog;
win.Loaded += (s, e) =>
{
result = saveFileDialog.ShowDialog();
};
win.ShowDialog();
return result;
}
Can you explain this line? win.Owner = this.shell; –
Catechetical
As a more generic WPF-ish for any type of FileDialog:
public static class ModalFileDialog
{
/// <summary>
/// Open this file dialog on top of all other windows
/// </summary>
/// <param name="fileDialog"></param>
/// <returns></returns>
public static bool? Show(Microsoft.Win32.FileDialog fileDialog)
{
Window win = new Window();
win.ResizeMode = System.Windows.ResizeMode.NoResize;
win.WindowStyle = System.Windows.WindowStyle.None;
win.Topmost = true;
win.Visibility = System.Windows.Visibility.Hidden;
win.Content = fileDialog;
bool? result = false;
win.Loaded += (s, e) =>
{
result = fileDialog.ShowDialog();
};
win.ShowDialog();
return result;
}
}
© 2022 - 2024 — McMap. All rights reserved.