Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this.Close(); doesn't work in window wpf

Tags:

c#

wpf

In wpf, window I am calling window forms. Before calling that I just want to close that window. Here is my code.

  public partial class MainWindow : MetroWindow
  {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void BtnIntroClick(object sender, RoutedEventArgs e)
        {

            PdfReader form = new PdfReader(1);

            form.ShowDialog();
            this.Close();

        }
   }

No error, but form is not closing. And in window form also, this.Close() in not working

 public partial class PdfReader : Form
 {
        public PdfReader(int page_num)
        {
            InitializeComponent();
            var executingFolder = System.AppDomain.CurrentDomain.BaseDirectory;
            var dbPath = System.IO.Path.Combine(executingFolder, "BiodermaProduct.pdf");
            axAcroPDF1.LoadFile(dbPath);

            axAcroPDF1.setCurrentPage(page_num);
        }

        private void PdfReader_FormClosed(object sender, FormClosedEventArgs e)
        {
           this.Opacity = 0;
           MainWindow w = new MainWindow();
           w.ShowDialog();

        }
 }
like image 442
Rashmi S Avatar asked Dec 19 '25 16:12

Rashmi S


1 Answers

It will close when you close your PdfReader form. Form.ShowDialog returns only when the form is closed. So this.Close() is not called until ShowDialog finishes.
What you can do is set this.Visibility = Visibility.Hidden before calling form.ShowDialog();

like image 198
wingerse Avatar answered Dec 22 '25 12:12

wingerse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!