-
More of a curiosity than anything
I wanted to create a form that I inherited all forms from, just so I can add
any functions I might need to all forms at once. I was using this so that
the MDI form could ask any child form which toolbar buttons should be
displayed. Originally I created a class called FormBase with just an empty
constructor in it and inherited from this but the forms designer didn't like
this. So I removed the class, created a form instead, put in the exact same
code and it worked. As far as I could tell everything was identical. What
was the difference?
--
Michael Culley
www.vbdotcom.com
-
Re: More of a curiosity than anything
> Originally I created a class called FormBase with just an empty
> constructor in it and inherited from this but the forms designer
> didn't like this. So I removed the class, created a form instead,
> put in the exact same code and it worked.
Michael: Did your FormBase class inherit System.Windows.Forms.Form?
--
Phil Weber
-
Re: More of a curiosity than anything
Yep, forgot to mention that. It definately inherited from Form because I
remember the icon changing from a class icon to a form icon.
--
Michael Culley
www.vbdotcom.com
"Phil Weber" <pweber@nospam.fawcette.com> wrote in message
news:3dbde748$1@tnews.web.devx.com...
> > Originally I created a class called FormBase with just an empty
> > constructor in it and inherited from this but the forms designer
> > didn't like this. So I removed the class, created a form instead,
> > put in the exact same code and it worked.
>
> Michael: Did your FormBase class inherit System.Windows.Forms.Form?
> --
> Phil Weber
>
>
-
Re: More of a curiosity than anything
"Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote
> So I removed the class, created a form instead, put in the exact same
> code and it worked. As far as I could tell everything was identical. What
> was the difference?
Can you provide a small example? I tried inheriting a form real early on
(To give all forms an AutoRedraw property) and did not see the problem
you describe.
LFS
-
Re: More of a curiosity than anything
"Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in
news:3dbe2f86@tnews.web.devx.com:
> The code I used was just
>
> Public Class FormBase
> Inherits System.Windows.Forms.Form
> End Class
>
> If I create this as a form I can inherit from it, as a class I can't,
> but everything is identical.
>
I think it's just a matter of compiling before you try to inherit from it.
The form editor is a bit picky about that. I've done exactly what you've
tried.
--
Rune Bivrin
- OOP since 1989
- SQL Server since 1990
- VB since 1991
-
Re: More of a curiosity than anything
The code I used was just
Public Class FormBase
Inherits System.Windows.Forms.Form
End Class
If I create this as a form I can inherit from it, as a class I can't, but
everything is identical.
--
Michael Culley
www.vbdotcom.com
"Larry Serflaten" <serflaten@usinternet.com> wrote in message
news:3dbe0851$1@tnews.web.devx.com...
> "Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote
> > So I removed the class, created a form instead, put in the exact same
> > code and it worked. As far as I could tell everything was identical.
What
> > was the difference?
>
> Can you provide a small example? I tried inheriting a form real early on
> (To give all forms an AutoRedraw property) and did not see the problem
> you describe.
>
> LFS
>
>
>
-
Re: More of a curiosity than anything
I tried compiling and it compiled without an error but I still couldn't
inherit from the class. Its no big deal, it works if I create it as a form,
I'm just curious as to what is going on.
--
Michael Culley
www.vbdotcom.com
"Rune Bivrin" <rune@bivrin.com> wrote in message
news:Xns92B656ACFB419runebivrincom@209.1.14.29...
> "Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in
> news:3dbe2f86@tnews.web.devx.com:
>
> > The code I used was just
> >
> > Public Class FormBase
> > Inherits System.Windows.Forms.Form
> > End Class
> >
> > If I create this as a form I can inherit from it, as a class I can't,
> > but everything is identical.
> >
>
> I think it's just a matter of compiling before you try to inherit from it.
> The form editor is a bit picky about that. I've done exactly what you've
> tried.
>
> --
> Rune Bivrin
> - OOP since 1989
> - SQL Server since 1990
> - VB since 1991
>
-
Re: More of a curiosity than anything
"Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote
> I tried compiling and it compiled without an error but I still couldn't
> inherit from the class. Its no big deal, it works if I create it as a form,
> I'm just curious as to what is going on.
A couple things to check;
For your base form project, go to Project properties and check or change
the Root namespace, and that the Output Type is set to Class Library.
Compile the project.
In your derived project, add a reference to your base DLL file via the
..Net components tab (I don't know that the tab makes a difference, but...)
On your Inherits line, start with the root namespace which should give you
intellisense all the way out to your base form.
(A Root name can be partitioned: Company.Product.Tool.XXX where
the text in the Root textbox will end at Tool and XXX will be the name
of your base project, )
Can you use your class library now?
LFS
-
Re: More of a curiosity than anything
Hi Larry,
They are both in the same project. Its no big deal, if a create it as a
class I cannot inherit from it, if I create the exact same code as a form I
can, I'm just curious as to why.
--
Michael Culley
www.vbdotcom.com
-
Re: More of a curiosity than anything
G'day Michael.
Take a look at your .vbproj file in a text editor. You will see a section
called <Files>. Each file in your project should be represented here. You
will notice that each file has a "subtype" element; most will be either
SubType = "Code"
or
SubType = "Form".
The IDE behaves slightly differently with each file depending on this subtype
- the behaviour that you are experiencing probably stems from this...
Cheers,
Paul
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
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|