|
-
Oct 31st, 2011, 09:42 PM
#1
Thread Starter
New Member
Inherit Form
Code:
Public Class aaMyForm
Inherits Windows.Forms.Form
Added some controls. Build it, add the .DLL as reference to my other project.
In my other project:
Code:
Imports MyLib
Public Class XForm
Inherits aaMyForm
The events from aaMyForm execute correctly but the controls added to it are not shown on XForm. I have found some info about set Modifiers Protected in order to be able to change the functionality of the controls but havent found anything about why the controls aren display on the XForm.
-
Oct 31st, 2011, 11:56 PM
#2
Re: Inherit Form
in your Solution Explorer, click the Show all files button, then open XForm.Designer.vb + change the inherits line from:
vb Code:
Inherits System.Windows.Forms.Form
to:
then delete that same line from Public Class XForm
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 1st, 2011, 11:54 AM
#3
Thread Starter
New Member
Re: Inherit Form
Hi Paul, it turns out that the XForm.Designer.vb was already inheriting from aaMyForm, so I just deleted the same line from Public Class XForm but still no control is shown.
-
Nov 1st, 2011, 02:05 PM
#4
Re: Inherit Form
delete any compiled code...(dlls, exes, etc)... zip up the projects (using winzip, don't make a rar file) and attach it... clearly something isn't right and what ever it is isn't coming through the posts ...
-tg
-
Nov 2nd, 2011, 09:57 AM
#5
Thread Starter
New Member
Re: Inherit Form
I think I found the problem. I was creating a new class that inherited from Form instead of creating a new form which I thought was pretty much the same (both are classes that inherit from form) but the new form, has the .designer.vb file where the InitializeComponent resides, while when creating a new class that inherits form Form doesn't and so the InitializeComponent is not on the Partial part of the class.
So the solution is creating MyForm class directly by adding a new form instead of creating a class that inherits from Form. Now if a form in a different project inherits from MyForm it does contain the controls. I would still like to know the exact reason for that. Thank you all.
-
Nov 2nd, 2011, 10:11 AM
#6
Re: Inherit Form
That's pretty much what .Paul. was saying in his first post. All forms inherit from Form. Any new form you create will also inherit from Form. This is a child class of Form. Any new form that you want to have the same functionality as that child class has to inherit from that child class and not from Form directly. However, any such new sub has to call the InitializeComponent method found in the child class. Unfortunately, InitializeComponent is declared Private in the child class, so the derived class can't call it directly. If you take a look at InitializeComponent, you see that that is where all the controls are being created, so if that method isn't called....you get none of those controls, because they were never created.
There are two possible solutions:
1) Make the child InitializeComponents Protected. This has some ramifications, so it might not be a good idea. The problem would be that the designer for the derived form will not work right.
2) In the constructor of the derived form, explicitly call MyBase.New
My usual boring signature: Nothing
 
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
|