|
-
Mar 3rd, 2010, 09:39 AM
#3
Re: Custom dialog in a class library
The only difference between forms in a class library and forms in a Windows Forms Application is the creation of default instances.
In a Windows Forms app, whenever you create a form, a default instance, which is basically a variable (of the same name as your form), is created too, which you can use:
In this code snippet, Form1 does not refer to the class Form1 at all. It refers to an instance of the Form1 class: the default instance.
Somewhere, in a hidden place (I don't even know where), there should be some kind of declaration that also does
Code:
Form1 = New Form1()
In a Class Library, no default instance is created, so you have to create your own. What you were trying was almost correct, but instead of creating a new instance of the Form class, you create a new instance of the Form1 class:
Now, use f instead of the name Form1.
The code cicatrix showed would work too but can be very dangerous if you don't know what you are doing. That code returns a new instance every time the ShowDialog method is called. That may become very confusing. If you call ShowDialog once and have the user edit something on the form, then close it, then use ShowDialog again, the data will be gone because the second time, a different instance of your form is shown.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|