Reputation: 7301
Hi I have a form and i want to open another form when user close the current form as you can see here :
private void frmDashboard_FormClosing(object sender, FormClosingEventArgs e)
{
this.Close();
frmConcerns a = new frmConcerns();
a.ShowDialog();
}
But when i click on the close button i get this error :
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll
Additional information: Error creating window handle.
Upvotes: 1
Views: 2901
Reputation: 56697
this.Close()
closes the current form - which is actually being done right now already because otherwise the FormClosing
event wouldn't have been invoked. Remove that line.
Also, if you want to show a dialog as a modal window, you should provide the parent form, so instead of calling a.ShowDialog();
rather call a.ShowDialog(this);
.
If the error is still there I can assure you that the code you've shown will be correct after the modifications I've suggested - I've done similar things before. In that case the error must occur in other parts of your code you've not shown us.
Upvotes: 1