Problems with visual inheritance

  • Thread starter Florian Fordermaier
  • Start date
F

Florian Fordermaier

Hello,

I have the following problem:

I developed a control base class(derived from
System.Windows.Forms.Control) which adds
functionality needed by all derived controls(i.e. access to plc). If I
subclass this base class and drop the child on a form, the control
doesn't paint anymore. Instead, the type name of the control is
displayed as a string within this control.
This confused me a little, so I tried several things to figure out the
problem:

I created a new solution, added a device application and a device class
library.
In the class library I simply defined a class without any code in it:

public class MyControlBase : System.Windows.Forms.Control
{
}

I add a reference to the class library in my device application, derive
a control from my base class, like

public class MyControl : MyControlBase
{
public override void OnPaint(PaintEventArgs e)
{
e.Graphics.Clear(Color.Red); // just to see if painting
works
}
}


This worked just fine.

So I made my "real" base class completly empty(i.e. commented all inner
code) so that it looked like the declaration of MyControlBase(see
above).(I also derived it only from Control and removed all interfaces
from the inheritance list)
Again, the control does not paint, but shows its type name as a string.

The only difference in my opinion between the project with the "real"
base class and my test base class is that I use non-CLS compatible
types(ushort/uint) within the assembly where the control base class is
declared. I need those in order to do some interop with native
code(e.g. semaphores/events/memorymapped files/...)

Could this be the cause for this confusing behaviour?

Please help.
Thanks in advance

Florian
 
F

Florian Fordermaier

Some additions:

I stumbled on the DesktopCompatibleAttribute a few minutes ago.
If I apply this attribute to my "real" base class and to the
subclass(everything coded in c#)
it works !!!!!! The control paints again !
If I derive from my base class in a vb.net project, it first complains
about the non-CLS compliance of my base class. After adding a
CLSCompliant attribute to it, it also doesn't work.
So it seems to me, that the problem only arises when I mix the
languages.
Or there is some other problem and I'm unable to figure it out.

Thanks again.
Florian
 

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