-
Sep 5th, 2010, 09:20 PM
#1
Thread Starter
Member
[RESOLVED] Custom "Override" Structure
Okay, essentially I have a drawing application, where I have custom classes for the various shape types (Circle, Rectangle, Star, etc.). I'm using the PropertyGrid control within the application to allow the user to change the properties of these shape classes (for example: location, dimensions, etc.). The problem I have is that the ToString method of the native PointF structure (System.Drawing.PointF) gives the following string:
This output is not desirable. I want it to be displayed how it is in the Designer Properties Panel. For example, the "Location" property of a control is displayed as:
1. Is there a way to override the ToString method of the System.Drawing.PointF structure?
2. Is there a different way to display the properties of the System.Drawing.PointF structure in the PropertyGrid within the application?
-
Sep 5th, 2010, 09:29 PM
#2
Re: Custom "Override" Structure
You can't override anything in a structure because you can't inherit a structure.
The behaviour you want is achieved using a TypeConverter. Check out the documentation for the Point structure and the PointF structure and compare the declarations of each. Notice that the Point structure is decorated with the TypConverter attribute and the PointF structure is not.
I'm not sure but it may be that, if you decorate your property with the TypeConverter attribute, you will get the behaviour you want. Of course, if the Framework contains no suitable TypeConverter class for the PointF structure, you'll have to define your own.
-
Sep 5th, 2010, 10:38 PM
#3
Thread Starter
Member
Re: Custom "Override" Structure
That's exactly what I was looking for!
I had to create my own TypeConverter. I'm not sure if I'm doing it the best way...but it works. The following is the snippet where the conversion happens:
Code:
Public Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
If destinationType.Equals(GetType(String)) Then
Dim p As PointF = CType(value, PointF)
Return String.Format("{0}, {1}", p.X, p.Y)
Else
Return MyBase.ConvertTo(context, culture, value, destinationType)
End If
End Function
-
Sep 5th, 2010, 10:55 PM
#4
Re: [RESOLVED] Custom "Override" Structure
I would suggest that you use .NET Reflector to see how it's done in the PointConverter class and then do it the same way.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|