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 / December 2004

Tip: Looking for answers? Try searching our database.

Custom Control with Custom Component as Property

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ttupper - 24 Dec 2004 02:41 GMT
I have made a custom control that has a property that is a custom component.

When I put the custom control on a form in the designer, the propery is
listed in the Properties window with a default value of (none).

I then put the custom component on the form and it goes in the Component
tray like it is supposed to.

I then drop down the property on the custom control and the only value ni
the list is (none).

The custom control is derived from TextBox so if I put a ContextMenu
component on the form and then drop down the ContextMenu property it shows
(none) and contextMenu1.

What attribute do I need to put on the component or what attribute do I need
to put on the property of the control to have it use the available components
of the correct type that are on the form???

Thanks for any help on this issue.
John Saunders - 24 Dec 2004 03:37 GMT
>I have made a custom control that has a property that is a custom
>component.
[quoted text clipped - 17 lines]
> components
> of the correct type that are on the form???

[TypeConverter(typeof(ComponentConverter))]

John Saunders
ttupper - 24 Dec 2004 17:03 GMT
I would think that this should go on the property of the control?

> >I have made a custom control that has a property that is a custom
> >component.
[quoted text clipped - 21 lines]
>
> John Saunders
John Saunders - 24 Dec 2004 19:36 GMT
>I would think that this should go on the property of the control?

Yes, that's correct.

John Saunders

>> >I have made a custom control that has a property that is a custom
>> >component.
[quoted text clipped - 24 lines]
>>
>> John Saunders
ttupper - 27 Dec 2004 19:47 GMT
I finally got a chance to test this and I don't think that I am doing this
correctly.

Here is the code for the Custom Control's property.  The property type is a
Custom Component.

#if NETCFDESIGNTIME       
[System.ComponentModel.Category("Custom")]       
[System.ComponentModel.Description("Allows the developer to associate a
Universal Scanner.")]
[System.ComponentModel.ParenthesizePropertyNameAttribute(true)]
[System.ComponentModel.TypeConverter(typeof(ComponentConverter))]
#endif

public UniversalScanner.Scanner UniversalScanner
{
get{return m_Scanner;}
set{m_Scanner = value;}
}

What am I doing wrong?

> >I would think that this should go on the property of the control?
>
[quoted text clipped - 30 lines]
> >>
> >> John Saunders
John Saunders - 27 Dec 2004 22:16 GMT
>I finally got a chance to test this and I don't think that I am doing this
> correctly.
[quoted text clipped - 18 lines]
>
> What am I doing wrong?

Your code looks correct (assuming that NETCFDESIGNTIME is defined). What is
the symptom?

Another few thoughts: try simplifying the example and using a different
Component type for the property. In particular, consider creating a simple
reproducer - NETCFDESIGNTIME isn't something you should have to think about
while solving this.

Also, try ReferenceConverter and see if that works any better.

John Saunders
ttupper - 27 Dec 2004 23:27 GMT
I am a little bit confused on how to apply the TypeConverter.

Just to restate what I am trying to do:  (and so I can make sense of it as
well)

I have a custom control (ControlA)
I have a custom component (ComponentB)
I build both of them so they are designer aware and can be added to the
toolbox
ControlA derives from a TextBox
ComponentB derives from Component
ControlA has a property (PropertyC) that is of type ComponentB

In a separate solution I create a form
I place ControlA on the form
I place ComponentB on the form
I go to the property tab for ControlA and see that it has a PropertyC
I drop down the list and all that is there is (none)
I was hoping to see the name of an instance of ComponentB

I put [System.ComponentModel.TypeConverter(typeof(ComponentConverter))] as
an attribute of the property

Do I need to create a custom Converter?

Should I put the TypeConverterAttribute on the ComponentB class?

Am I even in the right ballpark?

Thanks for your help--

> >I finally got a chance to test this and I don't think that I am doing this
> > correctly.
[quoted text clipped - 30 lines]
>
> John Saunders
Mick Doherty - 28 Dec 2004 01:14 GMT
I'm joining this thread a little late, so I apologise if this solution has
already been dismissed.

Does your component inherit from System.ComponentModel.Component
If not does it implement IComponent.

If so then you do not need any attributes to get your property to behave as
you described.

As a simple example, add a UserControl to your project.

Add this code to the standard code already in the class.

\\\
private MyComponent componentProperty = null;

public MyComponent MyProperty
{
 get
 {
   return componentProperty;
 }
 set
 {
   componentProperty = value;
 }
}
///

now add a new Component (called MyComponent) to your project.

Build the project.

add an instance of the usercontrol and several instances of MyComponent to
your form.

your UserControls MyProperty should display (none) and in it's dropdown list
should be a list of all the MyComponent objects on the form.

no need for TypeConverters at all, unless your component class does not
implement IComponent.

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

>I am a little bit confused on how to apply the TypeConverter.
>
[quoted text clipped - 66 lines]
>>
>> John Saunders
ttupper - 28 Dec 2004 18:51 GMT
Thanks for making me take a step back and look at it on a simpler level.

I took your advice in combination with using the corect mix of design time
builds to make this work.

Thank you both for helping solve this problem.

> I'm joining this thread a little late, so I apologise if this solution has
> already been dismissed.
[quoted text clipped - 108 lines]
> >>
> >> John Saunders

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.