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();
}
}
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With