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 / Design Time / March 2005

Tip: Looking for answers? Try searching our database.

user control design time integration

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan I - 03 Mar 2005 22:20 GMT
Hello experts.

I have a class called VisualAspect. This class stores information about
how to draw things (backcolor, forecolor, font, ...). This class is
complete with a TypeConverter (which returns a constructor based
InstanceDescriptor), DefaultValue attributes on every public property,
and ShouldSerializeXXX and ResetXXX methods on properties that cannot
provide constant/integral properties.

This class is used by my user control, which simplistically is laid out
as such:

public class Grid : System.Windows.Forms.UserControl
{
  // ctor/ other stuff

  VisualAspect normal_aspect = new VisualAspect();
  VisualAspect hottrack_aspect = new VisualAspect();

  [DesignerSerializationVisibility(Content)]  <- shortened, by u get it
  public VisualAspect AspectNormal
  { get... set... }

  [DesignerSerializationVisibility(Content)]
  public VisualAspect AspectHotTrack
  { get... set... }
}

Now, the problem is, the Forms designer won't serialize any modified
properties properly.

Here is a snippet from a form's code that contains my user control.

void InitializeComponent()
{
  VisualAspect visualAspect1 = new VisualAspect(); // not necessary-
already constructed !

  visualAspect1.BackColor = Color.Red; // ok- I set this in the
property grid

  Grid grid1 = new Grid(); // ok
  grid1.Location = ... // ok
  grid1.Size = ... // ok

  // No meaningful assignment is ever made in the code above, because
visualAspect1 goes out of scope.
}

Any thoughts or pointers to a good ComponentModel tutorial would be
appreciated since MSDN docs on this topic are cryptic and incomplete.

Dan I
joeycalisay - 04 Mar 2005 01:47 GMT
Can you provide some snippet for your VisualAspect class (is it a Component?
if it is, maybe this is the major cause of the problem)

> void InitializeComponent()
> {
>    VisualAspect visualAspect1 = new VisualAspect(); // not necessary-
already constructed !

This is perhaps because of your TypeConverter which returns an
InstanceDescriptor.  Do you really need a cutom TypeConverter? Perhaps what
you need is just the ExpandableObjectConverter class...

By the way, you don't need a set counterparts for your VisualAspects
property, you already have an instantiated it in your Grid Class, you only
need to modify its internal properties, making it readonly will suffice,
just like the WinForms Controls (ControlCollection) property.

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> Hello experts.
>
[quoted text clipped - 49 lines]
>
> Dan I
dan - 04 Mar 2005 04:51 GMT
Thanks joey.

I screwed around with it more and *just* about got it working.

The only reason I implemented a custom converter was because in the
future, the Grid (or other controls) may expose a collection for
VisualAspect objects- thereby the designer needs an instancedescriptor
to support the collection editor.

I did what you said and made the control's properties read-only- that
did the trick.

No, my VisualAspect class does not derive from component.

The only thing left (which I can live with), is that the PropertyGrid
displays the VisualAspect's string representation in a bold format, even
though *no* properties in the object have been modified.

That's no big deal though. I can learn to live with it.

Thanks for your quick reply- I'll send you a copy (when it is finished)
of a Gantt Chart component I'm working on for .Net.

Dan I

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.