Hello again,
I have created a class, and two forms, and the "app" works like it should. However, when I try to compile to a .dll it throws a Error "Reference to a non-shared member requires an object reference". This is exactly what Vulpes helped me with with an earlier project. However, I just can't seem to get a firm grasp on using textboxes and other form methods and properties in another form. I have attached the file for your reference. Anf If someone could recommend a great way to learn(book, dvd, etc..) about how to use classes with multiple forms and their properties, I'd appreciate it. I am bound and determined to learn how a class can be used on or with multiple forms.
Thanks,
Kevin
Loading
VulpesPosted Aug 25, 2011, 4:55 AM
Kevin DavisPosted Aug 25, 2011, 12:16 AM
However, the first way to do this that you mentioned, by using the Initilaize component methos, worked just fine. Thank you very much for your help and pointing me in the right direction.
Kevin
VulpesPosted Aug 24, 2011, 6:14 PM
There are many ways to obtain such references but, if you only intend to create a single instance of a form, then an easy way is to create a shared field in your Form class which makes this reference available to all other Forms or Classes within your application.
You can do this here as follows:
' In the Form1 class add the highlighted lines
' in your contact class amend the line which is giving the error as follows
Although I have a couple of 'heavy' books on Windows Forms, they don't discuss what to do when you have more than one form. In fact, even a 1500 page book can only skim the surface of what is a huge subject.
The best thing to do here is to learn by experience and you'll see this, or similar, questions asked many times on .NET forums with a range of possible things that you can do about it depending on the circumstances.
Another thing you could have to done here would have been to make no changes at all to Form1 but change the code in the AddContact() method as follows:
The Application.OpenForms collection contains references to all open forms and you can get a particular one using its name (normally the same as the class name). You need then to cast it to its actual type as the property returns a generic Form reference.