Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / September 2006

Tip: Looking for answers? Try searching our database.

Really odd problem with inheritance

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PureCode - 18 Sep 2006 23:07 GMT
Hi,

I bumped into a (to me) very strange problem. It took me nearly two days to
figure out what on Earth was happening.

I have three things in my test project:

1) Background.cs - Defines a background, basically a bunch of get/set
methods.
2) Base.cs - This is a UserControl that inherits from Panel and uses
Background.cs for it's background, also handles fully custom drawing of my
'panel'.
3) Test.cs - This is a UserControl that implements Base.cs to draw the
'panel' as a background for the control i am making.

As said, Background.cs contains the get/set methods that define the
background for the Base.cs 'panel'. Base.cs inherits the system Panel
control, overrides OnPaint and has a get/set pointing to Background.cs.
Test.cs is a plain UserControl where Base.cs is dropped on the control
(which provides the background for whatever i want Test.cs to do).

Base.cs defines Background as:

private Background = new Background(this);

The 'this' is needed because otherwise UserControl will not redraw in the
designer, basically i pass the Base.cs control to Background.cs so that i
can catch an event in Base.cs when Background changes (odd thing there too,
Invalidate() does NOT work, i have to Hide() and Show() the control in
Background.cs to raise the VisibleChanged event in Base.cs to know that
something has changed.. highly odd).

Now, the problem is as follows (not native english speaker, so i hope this
will be understandable):

When i add the Base.cs control to the Test.cs UserControl (drop it from the
toolbox onto the UserControl Designer) it adds a "Background background1 =
new Background();" and "base1.Background = background1;" to
Test.Designer.cs.

This totally screws up the redrawing in the designer as Background suddenly
doesn't know the control (Base.cs) anymore and as such, Base.cs doesn't know
that it needs to redraw when the Background properties are changed from the
UserControl. (So, changing Background properties doesn't show in the
Designer, until i run the test application where it does show the changes,
but the Designer NEVER shows the changes.)

When i remove the "Background background1 = new Background();" and
"base1.Background = background1;" from Test.Designer.cs (and point the
Background properties directly to the Base.cs control (base1.Background)
instead of 'background1), everything works as it should.. however, just
about every change i make in Test.cs, restores the problem all over again in
the Test.Designer.cs and i have to manually edit it again. As you can
imagine, this is enormously annoying as i have to manually edit the
Test.Designer.cs almost every time i make a single change.

Anyone have any clue why the UserControl keeps creating another Background
object and overwriting the one i create in Base.cs?

Thanks,

A confused Pure
Christof Nordiek - 20 Sep 2006 15:45 GMT
Hi,

look for DesignerSerializationVisibilityAttribute.
By this you can control if and how the property will be serialized into the
designer gereated code.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Since your Base.cs wants to control the content of this field itself.

BTW. your field declaration is private, so Test.cs shouldn't be able to
write into this. If there is a property to wich can access it, it should be
readonly.

> Hi,
>
[quoted text clipped - 58 lines]
>
> A confused Pure

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.