Link to home
Start Free TrialLog in
Avatar of PhilAI
PhilAIFlag for United Kingdom of Great Britain and Northern Ireland

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.ErrorProvider control.

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

Open in new window

Avatar of Bob Learned
Bob Learned
Flag of United States of America image

You should be able to use an alternate form of the DefaultValueAttribute to get what you need:

Example for System.Drawing.Color:
<DefaultValue(GetType(System.Drawing.Color), "248, 232, 192")>

The form is type and a string representation for the type.
Avatar of PhilAI

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".
Hmmm...I would have thought that this would work:

<DefaultValue(GetType(System.Drawing.Size), "16, 16")> _
Avatar of PhilAI

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

Open in new window

Did you try it as shown?

System.ComponentModel.DefaultValue(GetType(System.Drawing.Size), "16, 16"), _
Avatar of PhilAI

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.
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.
Avatar of PhilAI

ASKER

I am looking at the boldness in the designer properties window.
ASKER CERTIFIED SOLUTION
Avatar of PhilAI
PhilAI
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PhilAI

ASKER

Stupid VB.NET designer! Thanks.
Avatar of PhilAI

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.
No, my friend, I don't know how to answer that, but it sounds like a completely different question to answer anyway.