Creating New Components

malloc

New member
Joined
Aug 16, 2006
Messages
4
Location
South Africa
Programming Experience
5-10
Hey everyone,
I recently got myself a copy of VS 2005, and started playing around looking at the changes which was made since VS 6.
Unfortunately, like with most programs, the controls which comes bundled with VS 2005 (at least they come bundled), although good, are purely plain blunt.

Yeah, I know, so why not make my own *laugh*. Well that is why I am here.

I have not worked a lot with making custom Windows Library Controls, though I do know how to sit down, and create my own control, etc. There are still a few things I am trying to figure out:

a) Each control has a list of properties, now I know how to give a new control such properties, override existing properties, but how do you remove property which is predefined, for example when you create a control which Inherits it’s properties from a label, etc.

b) Also, how does one disable a certain property depending on what other properties have been set to? For example, let’s say I have a label which can be either a normal label or a hyperlink label, thus you would choose the type by setting the property.
1. when the label is a hyperlink label, there should be properties for ForeColorNormal, ForeColorHover, ForeColorMouseDown, ForeColorClicked, but;
2. when the label is a normal label, none of those four should be enabled, but there would be the normal ForeColor property.

c) Lastly, about properties, you see some controls which has (let’s call them) property groups, for example the font. There you would be able to choose the font name, size, style, etc. How is this achieved?
That is about it.

Kind regards,
MalloC
 
a) Each control has a list of properties, now I know how to give a new control such properties, override existing properties, but how do you remove property which is predefined, for example when you create a control which Inherits it’s properties from a label, etc.


My question is, why would you want to inherit a control and then remove the properties it has inherited. It's not possible to remove then from intellisense as they are part of the class. But you can add a designer and use the pre-filter properties method to remove them from the designer. However i would suggest that if you don't like a few properties that a control has look for it's base class and inherit that as it may not have those particular properties.

Also, how does one disable a certain property depending on what other properties have been set to? For example, let’s say I have a label which can be either a normal label or a hyperlink label, thus you would choose the type by setting the property.
1. when the label is a hyperlink label, there should be properties for ForeColorNormal, ForeColorHover, ForeColorMouseDown, ForeColorClicked, but;




Not sure what you mean by disabling a property here....

Lastly, about properties, you see some controls which has (let’s call them) property groups, for example the font. There you would be able to choose the font name, size, style, etc. How is this achieved?


Font is a class has it has those properties as members, it's as simple as that. Vb.net knows how to convert the font classes properties to and from a string by means of an in-built type converter you don't need to worry about it. Add a font property to yuor control an it will have those 'groups. If you were to implement your own class using custom types then you will need to create a type converter so vb.net knows how to convert them to and from a string.

 
My question is, why would you want to inherit a control and then remove the properties it has inherited. It's not possible to remove then from intellisense as they are part of the class. But you can add a designer and use the pre-filter properties method to remove them from the designer. However i would suggest that if you don't like a few properties that a control has look for it's base class and inherit that as it may not have those particular properties.
Well, I didn't think about using a component's base class, but for example, say I want to make a new control, which should not support a image, but it inherits the image property, I would surely want that to be not an option. Put this down as a learning curve for creating properties.

Not sure what you mean by disabling a property here....
Let's say I have a control with two properties which both is boolean, propertya and propertyb, now if propertya = false, then propertyb should be disabled (grayed out and cannot be set by the user), but if propertya = true, then the property can be set.

I have seen this with some controls, though I am not sure how this can be done.

Font is a class has it has those properties as members, it's as simple as that. As vb.net knows how to convert properties to and from a string by means of an in-built type converter you don't need to worry about it. Add a font property to yuor control an it will have those 'groups. If you were to implement your own class using custom types then you will need to create a type converter so vb.net knows how to convert them to and from a string.

Font was merely an example here, but I think I understand the concept now, mainly I would like to group certain properties together, for example, why make a control which you can custimize the style, but not have everything that affects the style grouped together.

Anyway, thanks for the reply. I will go and work with it a bit more.

Kind regards,
Malloc
 
Ah, maybe got the wrong end of the stick. Are you talking about grouping properties
together in the properties window in the designer? If so then it's all about attributes. The ones you need are the following..

VB.NET:
<Category("Appearance"), Decription("Is displayed at the bottom of the properties window"), 
defaultValue(Is show in bold and is not serialized in the generated code, 
when you change the property it is serialized)> _
Public Property DoSomething
Get..
 
 
End property

Ps contrary to popular belief the default value is not for say putting a certain text
in a textbox when a new control is added.

PPs If you are ever going to add an image property to your control you will need
one extra attribute because if you remove the image it will stick around in memory.
This attribute is called AmbientValue and that is because all properties that get there
info from external resources have an 'ambientvalue'.
 
Let's say I have a control with two properties which both is boolean, propertya and propertyb, now if propertya = false, then propertyb should be disabled (grayed out and cannot be set by the user), but if propertya = true, then the property can be set.

I have seen this with some controls, though I am not sure how this can be done.
Can't say I remember ever seeing this, I don't think it's possible.

About hybrid label/linklabel you don't need it because when it is time for such control to become either one you just add a normal control dynamically (and remove/hide the other if it's there), you could also add both in designer and just switch which is visible, this is less expensive than turning off the link stuff of a linklabel.
 
Just had a check on my system. Using the Developers Express (www.devexpress.com) and placing a SimpleButton on the form I got the following:

There is an expandable group called 'LookAndFeel' which has two properties which are 'disabled'. Though I did notice that they do not become enabled, when changing properties within the SimpleButton itself.

It must be that which I thought off. Anyway, thanks alot for the replies. Will see what I can get sorted out.
 
mmm. Well the only way i could think of to 'Disable' a property is to do something like the following...


VB.NET:
Public Shadows Property Text as String
Get
Throw New Exception("Property Not Supported")
End Get
Set (byval value As String)
Throw New Exception("Property Not Supported")
End Set
End Property

I'll have to look into the idea that you can make them appear disabled by greying them out. Must be something the've done in a custom designer.
 
Let's say I have a control with two properties which both is boolean, propertya and propertyb, now if propertya = false, then propertyb should be disabled (grayed out and cannot be set by the user), but if propertya = true, then the property can be set.
Can't say that I've ever seen this either.
What I have seen is a description of the property stating that the property is not valid if other property has certain value. Using the description attribute vis has shown above:
VB.NET:
<System.ComponentModel.Description("Normal Description.... Not valid if propertya = false")> _
 
Properties are disabled because they are readonly.... If the usefullness of a property is dependent on the setting of another, bot h properties should be enabled, but the one should only be used if the other is set. OTherwise, it is ignored.

That's the way I've done it in the past, and that's typicaly the way I've seen it.

-tg
 
Back
Top