Closing OpenFileDialog/SaveFileDialog

后端 未结 4 1729
星月不相逢
星月不相逢 2020-12-11 06:29

We have a requirement to close child form as part of auto logoff. We can close the child forms by iterating Application.OpenForms from the timer thread. We are not able to c

4条回答
  •  孤街浪徒
    2020-12-11 06:59

    [workaround] here is example:

    You should define fully transparent window ex. "TRANSP";

    Every time you need to show dialog, you need to show TRANSP and pass TRANSP as a parameter to ShowDialog method.

    When the application shuts down - call Close() Method of TRANSP window. Child dialogs will close.

        public partial class MainWindow : Window
    {
        OpenFileDialog dlg;
        TranspWnd transpWnd;
    
        public MainWindow()
        {
            InitializeComponent();
    
            Timer t = new Timer();
            t.Interval = 2500;
            t.Elapsed += new ElapsedEventHandler(t_Elapsed);
            t.Start();
        }
    
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                transpWnd.Close();
            }), null);
        }
    
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            transpWnd = new TranspWnd();
            transpWnd.Visibility = System.Windows.Visibility.Hidden; //doesn't works right
            transpWnd.Show();
    
            dlg = new OpenFileDialog();
            dlg.ShowDialog(transpWnd);
        }
    }
    

提交回复
热议问题