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 / January 2005

Tip: Looking for answers? Try searching our database.

class property default value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gerry - 03 Jan 2005 12:26 GMT
Using vs.net 2003 , I have the 2 classes defined below compiled into a
designtime library and added to the toolbox.
If I drop a Ctl object on a form I get the expandable Prop property in the
property grid for the control as I expect - similar to the way the Font or
Size properties are shown.
I am trying to use the DefaultProperty attribute to allow editing of the
Prop.Prop1 property in the property grid without expanding the Prop property
, the same way that Font allows you to edit/select  the font name without
expanding the Font property.
Obviously I am doing something wrong , because what I am getting is just the
name of the property object "Ctl1.Prop" displayed beside the expandable
property Prop.

Am I using the wrong attibute to do this or am I missing a step somewhere ?

Gerry

// property class
[DefaultProperty("Prop1")]
public class Prop : Component
{
   [Description("Property Description 1")]
   [NotifyParentProperty(true)]
   public int Prop1
   {
       get { return 1; }
   }
   [Description("Property Description 2")]
   [NotifyParentProperty(true)]
   public int Prop2
   {
       get { return 2; }
   }
}

// control class
public Ctl : Control
{
   private readonly Prop prop;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
   public Prop Prop
   {
       get { return prop; }
   }
   public Ctl()
   {
       prop=new Prop();
   }
}
joeycalisay - 04 Jan 2005 01:23 GMT
I believe you're missing on type converters.  Try to browse the section on
this article of type converters and see if it helps:
http://www.awprofessional.com/articles/printerfriendly.asp?p=169528

> Using vs.net 2003 , I have the 2 classes defined below compiled into a
> designtime library and added to the toolbox.
[quoted text clipped - 46 lines]
>     }
> }
gerry - 04 Jan 2005 07:16 GMT
Thanks Joey ,

I had read through this document but thought that this was not required for
simple types due to my complete misunderstanding of the DefaultProperty
attribute.
After a little playing around, I couldn't get this to do what I wanted, but
at least I got rid of the ugly component name.
I am displaying some 'friendly' readonly text based on the property's
property values and all value changes are made to the individual properties
of the expanded property.

What I had wanted to do was edit a default property here rather than a
string representing all properties.

I have some further realted questions but will start a new thread for these.

Gerry

> I believe you're missing on type converters.  Try to browse the section on
> this article of type converters and see if it helps:
[quoted text clipped - 42 lines]
> > {
> >     private readonly Prop prop;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
> >     public Prop Prop
> >     {
[quoted text clipped - 5 lines]
> >     }
> > }
Ulrich Sprick - 08 Jan 2005 18:31 GMT
Hy gerry,

as joey pointed out, you need a type converter, which is used to convert the
property value (which is an object with its own child properties) into a
string (to be displayed in the property browser) and from string to a new
object.

Override the [Can]ConvertTo() methods to provide the string that you want to
be seen.

Override [Can]ConvertFrom(), specify that you can convert from string type.
Create a new instance of your object in ConvertFrom() in order to return it
later. The value parameter is a string that will only have the information
that you supplied in ConvertTo() above, so you will need to access the other
object properties via TypeDescriptorContext.Instance in order to create a
completely initialized object of your type.

The msdn has a topic "Implementing a Type Converter", which describes it
quite well.

hTH, ulrich.

> Thanks Joey ,
>
[quoted text clipped - 75 lines]
> > >     }
> > > }

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.