Click here to Skip to main content
15,881,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
&I have two forms; InputForm and PrintAvailFrm.
I have a print button on the InputForm with the following code;
VB
Private Sub PrintAvail_Click(sender As Object, e As EventArgs) Handles PrintAvail.Click
        PrintAvailFrm.Show()
        PrintAvailFrm.PAOpponents.Text = Me.Opponents.Text 'Read data on Input form and writes it on the PrintAvailFrm
        PrintAvailFrm.PAVenue.Text = Me.Venue.Text
        PrintAvailFrm.PADate.Text = Me.DatePicker.Text
        PrintAvailFrm.PATime.Text = Time.Text
        PrintAvailFrm.PATeamSize.Text = TeamSize.Text
        PrintAvailFrm.PAMatchCaptain.Text = MatchCaptain.Text

        Me.Close()
    End Sub



When I try and run the code I get this error;
An unhandled exception of type 'System.InvalidOperationException' occurred in MatchManagement.exe

Additional information: An error occurred creating the form. See Exception.InnerException for details. The error is: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "MatchManagement.PrintAvailFrm.resources" was correctly embedded or linked into assembly "MatchManagement" at compile time, or that all the satellite assemblies required are loadable and fully signed.


Can anyone tell me what I need to do to solve this?

Thanks
Posted

Well, see the inner exception for detail, and provide comprehensive expression information, especially the stack, and show the code where the exception was thrown; only then you can hope some help on this part.

Now, as to the opening and closing a form. Paradoxically, even thought a form can be closed, there is no such thing as "open a form". Come to think about, how anything which was never closed can be "opened". You create a form, show it; that's all. As to the rest of the code showing, you do it all wrong. Practically, the code when you shown a form and then close is useless in nearly all cases. You rarely need to close a form; in practice, you only need to close the main form at the very end, which leads, to application exit. Let's consider different models.

First, you can let the user work with the form until all changes are done, not touching other forms. Then you need to make it modal, which is done using System.Windows.Forms.Form.ShowDialog:
https://msdn.microsoft.com/en-us/library/c7ykbedk%28v=vs.110%29.aspx[^].

If you don't want it to be modal, it's more difficult, because the use has more choices. Closing such form makes no sense at all, but the user can close it. Even it that case, it's better to handle closing it and hide it instead. Only then that form can be used later again, in the same state. This is done by handling the event Form.FormClosing:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.formclosingeventargs%28v=vs.110%29.aspx[^].

This event can be cancelled to prevent actual closing. Call Form.Hide instead. Do it only for CloseReason equal to System.Windows.Forms.CloseReason.UserCloseing, to allow actual closing at the end of application lifetime.

Also, as in this case you end up having several non-modal forms opened at the same time, make sure you use the owner-owned relationships. It's enough to make all such forms owned by the main form:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.removeownedform(v=vs.110).aspx[^].

It's harder to explain the change in behavior, it's easier to make the forms owned and watch the difference in behavior. Owning keeps the application integrity; you keep all forms of the same application together in Z-order. If you don't, any other application's form can get between your application's forms, which is ugly, inconvenient.
Usually, for owned forms, it comes with one more option: not showing them in a task bar: https://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar(v=vs.110).aspx[^].

And, finally, even better idea would be avoiding those non-modal forms at all and keep all functionality in one single form (I don't count modal forms here). Instead of separate forms, you can use panels, tab page (of the TabControl) or something else. You can build more complex docking interface like the one of Visual Studio, but this is a very complicated work (or you can use 3rd-party solutions). Simple tabbed interface works very well.

—SA
 
Share this answer
 
v2
Comments
BillWoodruff 14-Mar-15 8:15am    
+5 very thorough answer !
Somehow the PrintAvail.vb was empty and the form had been deleted. Recreated the form and all is OK.

Thanks for any assistance.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900