Question Expose properties in user control

jswota

Well-known member
Joined
Feb 23, 2009
Messages
49
Programming Experience
Beginner
Hi,

I am new to developing custom user controls in VB.Net. I am creating a graphical interface that will display CNC files. I have already created a class that reads and analyzes the CNC file and this class is used in my custom control to get the information that is to be drawn in the custom control. The class has many properties available that affect the way in which the CNC data is processed. I set some of these properties at design time within the custom control but what i am looking to do is expose the class properties to the user through the custom control.

For instance:
The class has a boolean property called Class.AlignHoles. How can i set up my control to show this property like CustomControl.AlignHoles. Do i have to replicate the properties within the custom controls or is it a matter of scope?

Any help will be greatly appreciated.

Thanks,
Joel
 
The safest way would be to replicate the properties, thus giving your UI control more control over what's happening. You could just elevate the scope of it's usage of the class to Friend or Public which would make it's properties available, via ControlInstance.ClassName.Property/Method
 
Thanks for the reply.

I think what you are saying "You could just elevate the scope of it's usage of the class to Friend or Public which would make it's properties available, via ControlInstance.ClassName.Property/Method" is what i want to do. If my user control uses the CNC class, and the CNC class has three properties (Property1, Property2 and Property3), then i want to be able to click on the user control that is placed on my form and set the UserControl.CNC.Property1 setting at design and runtime. How do i do this?

I tried to create a private instance of the CNC class in my user control that is exposed by a public property but it doesn't work.

VB.NET:
Private m_CNC As cls_CNC
Public Property CNC() As cls_CNC
    Get
        Return m_CNC
    End Get
    Set(ByVal value As cls_CNC)
        m_CNC = value
    End Set
End Property

Can you please tell me what i am doing wrong?

Thanks again,
Joel
 
jswota said:
If my user control uses the CNC class, and the CNC class has three properties (Property1, Property2 and Property3), then i want to be able to click on the user control that is placed on my form and set the UserControl.CNC.Property1 setting at design and runtime. How do i do this?
To do that you have to define a TypeConverter, see for example this article: Getting the Most Out of the .NET Framework PropertyGrid Control Read through or go to the 'Support for Custom Types' part.
 
Back
Top