Re: [2.0] Form.ActiveForm
Firstly, you wouldn't use the ActiveForm property unless you specifically wanted a reference to the active form, whatever form that might be. If you specifically want a reference to your startup form then that's just not appropriate. Using the ActiveForm property is good programming if you want a reference to the active form, other wise it's not.
Secondly, the ActiveForm property is static, so you call it on the Form class, not on an instance of the class.
If you can't directly pass a reference to the main form to the places it's needed then you will need to use a global variable. You could use a static class, which is the C# equivalent of a VB module, or you could use a Singleton class. Either way you'd be setting and getting the main form reference via a static property so you'd have access to it from anywhere.
Re: [2.0] Form.ActiveForm
The whole idea sounds a bit messy. I only need to be able to add controls to the forum. There must be a better solution than creating a static class or singleton JUST for calling the Controls property of the main form.
Hopefully a better solution? :(
Re: [2.0] Form.ActiveForm
I fail to see what's bad about the solution provided such that a better one need be sought. The "proper" way to get access to your main form elsewhere is to pass a reference to it where it's needed. THAT is the better solution. If you can't or won't do that then the alternative is as I described. VB has the My.Application.ApplicationContext.MainForm property; C# does not. Unless you have some magic that I don't know about then you will use the solution provided.
Re: [2.0] Form.ActiveForm
Re: [2.0] Form.ActiveForm
Quote:
Originally Posted by jmcilhinney
Unless you have some magic that I don't know about then you will use the solution provided.
You will use that solution because that's the only solution available, not just because I said so. :)