"friend" accessor and inherited forms

G

Guest

Interesting behavior I came across today where a child form has full access
to a base form class' controls, but you can only modify the controls'
properties in code, not in the visual designer. Here's how you can reproduce
it:

New Winforms project
On Form1, drop a visual control. I'll use a panel in this example.
Make sure Panel1 modifier is set to "Friend"
Build project
Add another form - this one an inherited form. Set it to inherit from Form1.

At this point, you can go to the Form2 code editor and you will indeed have
full access to Me.Panel1 and all its properties.

However, if you go to the visual designer of Form2 and click on Panel1,
you'll notice in the F4 properties window, all of the properties are greyed
out as if Panel1 was declared "Private".

After some searching here, I noticed that this was identified as a bug in
VB.NET 2003, however, the same behavior happens in 2005 as well. Is this
still considered a bug? Or has it been upgraded to "feature"? :)
 
C

Cor Ligthert [MVP]

Vark,

Can you give us the link where this was notified as a bug in version 2003.

As you describe it, does it looks for me so obvious that you cannot change
the properties from a base class inside a derived object, in another way
than overriding it if that is possible.

Cor
 
G

Guest

I'm using the web interface for these newsgroups, so I don't know how to link
to an article, however, if you search against "protected friend" in the
dotnet.framework.windowsforms group, there's a thread titled "Inherited Menus
and Modifiers" where someone mentions it being in an internal bug database.

However, now that I read that, that post does specify "protected friend"
which may or may not work these days. That's moot, though since I can't use
protected friend (I don't want child classes outside the assembly to have
access). I unfortunately am limited to using friend only.

I've used a temporary work around - set it as protected, which gives me
designer support, then right before the build copy all the
InitializeComponent code for that control into the Form New() and change the
control to friend. It works for now, but it does seem a bit kludgy to do it
this way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top