I have a Windows.Forms component that has a mySize property that returns a size structure. My intention was for this property to calculate the returned mySize automatically depending on the size of the component, if mySize was not set explicitly, in which case return the value set mySize. Unfortunately, now when I embed the component in the form, the Windows Forms developer decided to start the explicit generation and set the value of the mySize property, which correctly clicks me.
So I need to set DefaultValue so that the Designer leaves and leaves me alone.
I read the answers regarding System.ComponentModel.DefaultValue, so I know that I have to manually set the property value in the constructor, but the answers and documentation that I found relate to setting DefaultValue of False, constant.
The dimensional structure is not constant, so the VB compiler gets confused, telling me that I cannot set the size as the DefaultValue for the font size property, because sizes are not constants.
It makes my brain hurt.
I can probably create code around the problem by creating the getMySize and setMySize methods instead of using the property, but I would like to know if there is any way to set the default property for size.
NB: I do not use mySize as some kind of abnormal attempt to override the Size property (which has a DefaultValue value of 150x150, so SOMETHING seems to be able to set DefaultValues for sizes); mySize is just the size value required by the class.
source
share