PhilAI
asked on
DefaultValueAttribute and System.Drawing.. objects
I would like to use the DefaultValueAttribute to set a default for a property that returns a System.Drawing.Size and another property that returns a System.Drawing.Icon.
My other challenge is that my Icon property returning System.Drawing.Icon is simply accessing a child control with my own user control and exposing it to the user, so I want to pass through the DefaultValueAttribute defined by that.
erpPoSErrorProvider in the sample code is a System.Windows.Forms.Error Provider control.
Answers welcome in VB.NET or C#.
My other challenge is that my Icon property returning System.Drawing.Icon is simply accessing a child control with my own user control and exposing it to the user, so I want to pass through the DefaultValueAttribute defined by that.
erpPoSErrorProvider in the sample code is a System.Windows.Forms.Error
Answers welcome in VB.NET or C#.
''' <summary>
''' Get/Set the System.Drawing.Icon that is displayed next to a control
''' when an error description string has been set for the control.</summary>
<System.ComponentModel.Description("Get/Set the System.Drawing.Icon that is displayed next to a control when an error description string has been set for the control."), _
System.ComponentModel.Category("Appearance"), _
System.ComponentModel.DefaultValue("(Icon)"), _
System.ComponentModel.Browsable(True), _
System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always), _
System.ComponentModel.Localizable(True)> _
Public Property Icon() As System.Drawing.Icon
Get
Return Me.erpPoSErrorProvider.Icon
End Get
Set(ByVal value As System.Drawing.Icon)
Me.erpPoSErrorProvider.Icon = value
End Set
End Property
ASKER
Can you show me an example of doing that with System.Drawing.Size?
And do you know of a way to carry through the default from the ErrorProvider control, or creating a default for System.Drawing.Icon?
I have tried the string variation for System.Drawing.Size, but no success with: "16, 16", or "Width = 16, Height = 16".
And do you know of a way to carry through the default from the ErrorProvider control, or creating a default for System.Drawing.Icon?
I have tried the string variation for System.Drawing.Size, but no success with: "16, 16", or "Width = 16, Height = 16".
Hmmm...I would have thought that this would work:
<DefaultValue(GetType(Syst em.Drawing .Size), "16, 16")> _
<DefaultValue(GetType(Syst
ASKER
Nope, it doesn''t work :o( That's why I decided to post this question.
Private Const cDefaultSizeAsString As String = "16, 16"
''' <summary>
''' Get/Set the height and width of the control.</summary>
<System.ComponentModel.Description("Get/Set the height and width of the control."), _
System.ComponentModel.Category("Appearance"), _
System.ComponentModel.DefaultValue(GetType(System.Drawing.Size), cDefaultSizeAsString), _
System.ComponentModel.Browsable(True), _
System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always), _
System.ComponentModel.Localizable(True)> _
Public Shadows Property Size() As System.Drawing.Size
Get
Return MyBase.Size
End Get
Set(ByVal value As System.Drawing.Size)
MyBase.Size = value
End Set
End Property
Did you try it as shown?
System.ComponentModel.Defa ultValue(G etType(Sys tem.Drawin g.Size), "16, 16"), _
System.ComponentModel.Defa
ASKER
Yes, before I made it into a constant - still no success.
I've looked around online and I cannot seem to figure this one out - it's no big deal, just confused me.
I've looked around online and I cannot seem to figure this one out - it's no big deal, just confused me.
When you say "no success", I am thinking that you are looking for it to set the default size value. That is not what the DefaultValueAttribute does. That attribute is used to determine if the property is displayed in bold (changed) or normal (default value) in the property grid. If you want the default size value for the property, you need to do that a different way.
ASKER
I am looking at the boldness in the designer properties window.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Stupid VB.NET designer! Thanks.
ASKER
Any ideas to the other object?
My other challenge is that my Icon property returning System.Drawing.Icon is simply accessing a child control with my own user control and exposing it to the user, so I want to pass through the DefaultValueAttribute defined by that.
My other challenge is that my Icon property returning System.Drawing.Icon is simply accessing a child control with my own user control and exposing it to the user, so I want to pass through the DefaultValueAttribute defined by that.
No, my friend, I don't know how to answer that, but it sounds like a completely different question to answer anyway.
Example for System.Drawing.Color:
<DefaultValue(GetType(Syst
The form is type and a string representation for the type.