PC Review


Reply
Thread Tools Rate Thread

How do I create partial class to be nested under the main class file?

 
 
Joseph Geretz
Guest
Posts: n/a
 
      28th Mar 2007
When I create a Form, the VB IDE creates the following files in the
following hierarchy:

Form1.cs
Form1.Designer.cs
Form1.resx

Both Form1.cs and Form1.Designer.cs are partial implementations of a single
physical class definition. The VB IDE properly recognizes Form1.cs as a Form
(i.e. double-clicking opens the Form designer). It also recognizes
Form1.Designer.cs as additional code implementation. It properly nests this
class file under Form1.cs and double-clicking the file in the IDE opens to a
code window, rather than a Form design window. So far so good.

I'd like to extend the Form interface with a bunch of my own methods. So I
create a new class, Form1.Interface.cs, defined as follows:

partial class Form1
{
internal void DoThis()
{
}
internal void DoThat()
{
}

I'd like Form1.Interface.cs to behave just as Form1.Designer.cs does. That
is, I'd like this class to be nested beneath Form1.cs to make it obvious
that Form1.Interface.cs is a partial class addition to the partial class
defined in Form1.cs. I'd also like this class to open in the IDE just as
Form1.Designer.cs does; that is, double-clicking this module should open a
code window, not a Form design window.

But I can't get either of these to happen. My module Form1.Interface.cs is
treated by the IDE as though it is a Form. It doesn't appear nested under
Form1.cs and double-clicking it opens a Form design windows which is totally
inappropriate since this module is not intended to implement any visual form
elements at all!

(BTW, the compiler properly aggregates this into a single Form1 class
implementation. So there's no problem as far logical software construction
is concerned. However, it would be nice if I could get the IDE to recognize
the relationship between Form1.cs and Form1.Interface.cs and to properly
deal with this relationship (i.e. nesting and default open action) just as
it does with Form1.cs and Form1.Designer.cs.)

What am I doing wrong?

Thanks for your help!

- Joseph Geretz -


 
Reply With Quote
 
 
 
 
Joseph Geretz
Guest
Posts: n/a
 
      28th Mar 2007
By editing the .csproj file I was able to achive the desired goal. I
changed:

<Compile Include="Form1.Interface.cs">
<SubType>Form</SubType>
</Compile>

to

<Compile Include="Form1.Interface.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>

which is equivalent to the definition which I found for Form1.Designer.cs.

<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>

Having done this, Form1.Interface.cs now behaves exactly like
Form1.Designer.cs.

However, this is going to be VERY cumbersome if we need to do this manually
for all such partial classes which we create. Isn't there any way to do this
via the IDE, without having to resort to manually editing the .csproj file
in NotePad?

Thanks!

- Joseph Geretz -

"Joseph Geretz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When I create a Form, the VB IDE creates the following files in the
> following hierarchy:
>
> Form1.cs
> Form1.Designer.cs
> Form1.resx
>
> Both Form1.cs and Form1.Designer.cs are partial implementations of a
> single physical class definition. The VB IDE properly recognizes Form1.cs
> as a Form (i.e. double-clicking opens the Form designer). It also
> recognizes Form1.Designer.cs as additional code implementation. It
> properly nests this class file under Form1.cs and double-clicking the file
> in the IDE opens to a code window, rather than a Form design window. So
> far so good.
>
> I'd like to extend the Form interface with a bunch of my own methods. So I
> create a new class, Form1.Interface.cs, defined as follows:
>
> partial class Form1
> {
> internal void DoThis()
> {
> }
> internal void DoThat()
> {
> }
>
> I'd like Form1.Interface.cs to behave just as Form1.Designer.cs does. That
> is, I'd like this class to be nested beneath Form1.cs to make it obvious
> that Form1.Interface.cs is a partial class addition to the partial class
> defined in Form1.cs. I'd also like this class to open in the IDE just as
> Form1.Designer.cs does; that is, double-clicking this module should open a
> code window, not a Form design window.
>
> But I can't get either of these to happen. My module Form1.Interface.cs is
> treated by the IDE as though it is a Form. It doesn't appear nested under
> Form1.cs and double-clicking it opens a Form design windows which is
> totally inappropriate since this module is not intended to implement any
> visual form elements at all!
>
> (BTW, the compiler properly aggregates this into a single Form1 class
> implementation. So there's no problem as far logical software construction
> is concerned. However, it would be nice if I could get the IDE to
> recognize the relationship between Form1.cs and Form1.Interface.cs and to
> properly deal with this relationship (i.e. nesting and default open
> action) just as it does with Form1.cs and Form1.Designer.cs.)
>
> What am I doing wrong?
>
> Thanks for your help!
>
> - Joseph Geretz -
>



 
Reply With Quote
 
Joseph Geretz
Guest
Posts: n/a
 
      29th Mar 2007
> However, this is going to be VERY cumbersome if we need to do this
> manually for all such partial classes which we create. Isn't there any way
> to do this via the IDE, without having to resort to manually editing the
> .csproj file in NotePad?


I guess not :-(

http://forums.microsoft.com/MSDN/Sho...66418&SiteID=1

Pity.

- Joe Geretz -

"Joseph Geretz" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> By editing the .csproj file I was able to achive the desired goal. I
> changed:
>
> <Compile Include="Form1.Interface.cs">
> <SubType>Form</SubType>
> </Compile>
>
> to
>
> <Compile Include="Form1.Interface.cs">
> <DependentUpon>Form1.cs</DependentUpon>
> </Compile>
>
> which is equivalent to the definition which I found for Form1.Designer.cs.
>
> <Compile Include="Form1.Designer.cs">
> <DependentUpon>Form1.cs</DependentUpon>
> </Compile>
>
> Having done this, Form1.Interface.cs now behaves exactly like
> Form1.Designer.cs.
>
> However, this is going to be VERY cumbersome if we need to do this
> manually for all such partial classes which we create. Isn't there any way
> to do this via the IDE, without having to resort to manually editing the
> .csproj file in NotePad?
>
> Thanks!
>
> - Joseph Geretz -
>
> "Joseph Geretz" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> When I create a Form, the VB IDE creates the following files in the
>> following hierarchy:
>>
>> Form1.cs
>> Form1.Designer.cs
>> Form1.resx
>>
>> Both Form1.cs and Form1.Designer.cs are partial implementations of a
>> single physical class definition. The VB IDE properly recognizes Form1.cs
>> as a Form (i.e. double-clicking opens the Form designer). It also
>> recognizes Form1.Designer.cs as additional code implementation. It
>> properly nests this class file under Form1.cs and double-clicking the
>> file in the IDE opens to a code window, rather than a Form design window.
>> So far so good.
>>
>> I'd like to extend the Form interface with a bunch of my own methods. So
>> I create a new class, Form1.Interface.cs, defined as follows:
>>
>> partial class Form1
>> {
>> internal void DoThis()
>> {
>> }
>> internal void DoThat()
>> {
>> }
>>
>> I'd like Form1.Interface.cs to behave just as Form1.Designer.cs does.
>> That is, I'd like this class to be nested beneath Form1.cs to make it
>> obvious that Form1.Interface.cs is a partial class addition to the
>> partial class defined in Form1.cs. I'd also like this class to open in
>> the IDE just as Form1.Designer.cs does; that is, double-clicking this
>> module should open a code window, not a Form design window.
>>
>> But I can't get either of these to happen. My module Form1.Interface.cs
>> is treated by the IDE as though it is a Form. It doesn't appear nested
>> under Form1.cs and double-clicking it opens a Form design windows which
>> is totally inappropriate since this module is not intended to implement
>> any visual form elements at all!
>>
>> (BTW, the compiler properly aggregates this into a single Form1 class
>> implementation. So there's no problem as far logical software
>> construction is concerned. However, it would be nice if I could get the
>> IDE to recognize the relationship between Form1.cs and Form1.Interface.cs
>> and to properly deal with this relationship (i.e. nesting and default
>> open action) just as it does with Form1.cs and Form1.Designer.cs.)
>>
>> What am I doing wrong?
>>
>> Thanks for your help!
>>
>> - Joseph Geretz -
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an instance of user control in a class(simple) file notin Page class file? chandan Microsoft ASP .NET 2 3rd Dec 2007 06:01 AM
Re: How to create Windows Form partial class file? PS Microsoft Dot NET Framework Forms 1 29th Mar 2007 03:46 AM
Re: How to create Windows Form partial class file? Joseph Geretz Microsoft Dot NET Framework Forms 0 28th Mar 2007 12:48 AM
call a mnuFileNew_Click method from a Main MDI class from another class (can be a MdiChild class.. )? M. G, Microsoft Dot NET Framework Forms 1 31st May 2006 06:28 AM
nested native class in managed class in VC8 not allowed?? Lonewolf Microsoft VC .NET 9 3rd Jan 2006 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:48 AM.