-
Sep 5th, 2010, 10:53 PM
#1
Thread Starter
Member
[RESOLVED] Setting the Attributes for Native Structures
In a previous post (http://www.vbforums.com/showthread.php?t=626818) I needed to change how the values of an object's properties were displayed. In my case, I wanted to change how the native System.Drawing.PointF structure was displayed. If you check the post, it was resolved by using a TypeConverter.
Now, my next question is how do I give existing properties attributes? For example, the System.Drawing.PointF structure has three properties: X, Y, and IsEmpty. I would like to give the X and Y properties descriptions. Also, I would like to hide the IsEmpty property, i.e., Browsable(False).
-
Sep 5th, 2010, 11:15 PM
#2
Re: Setting the Attributes for Native Structures
You can't do that with structures I'm afraid. With classes, you can inherit them and then either override or shadow the base properties with your own and then apply whatever attributes you like. You can't inherit structures so you can't override or shadow their properties. What you may be able to do is define your own type that wraps the existing type. You then get to define all the functionality, e.g.
vb.net Code:
Public Structure MyPointF Private p As PointF Public Property X() As Single Get Return p.X End Get Set(ByVal value As Single) p.X = value End Set End Property '... End Structure
-
Sep 6th, 2010, 12:08 AM
#3
Thread Starter
Member
Re: Setting the Attributes for Native Structures
What you may be able to do is define your own type that wraps the existing type
If I create my own structure, how will methods that require the original structure be effected?
For example, the System.Drawing.Graphics class has a DrawPolygon method that is overloaded with either Point() or PointF() as parameters. If I call DrawPolygon with MyPointF() as the parameter, it will result in an error.
Is this another TypeConverter issue?
-
Sep 6th, 2010, 12:37 AM
#4
Re: Setting the Attributes for Native Structures
Obviously you can't use your custom type where some other type is expected. Your custom type is wrapping the other type though, so all you do is pass the wrapped value instead of the wrapper, e.g.
vb Code:
Dim p As PointF = myCustomStructure.PointF
where that PointF property exposes the 'p' field from my previous code sample.
The wrapper is for the benefit of the designer, so that you can expose the desired attributes to it. For anything else you use the original type.
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
|