Property Inspector

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
I have created a structure as shown below
VB.NET:
Public Structure MarginStruc
    Public Left As Integer
    Public Top As Integer
    Public Width As Integer
    Public Height As Integer
    Public Sub New(ByVal iLeft As Integer, ByVal iWidth As Integer, ByVal iTop As Integer, ByVal iHeight As Integer)
        Left = iLeft
        Width = iWidth
        Height = iHeight
        Top = iTop
    End Sub
End Structure
I have then created a public property within a user control in the hope that I can set the individual values via the property inspector just as I do with the size and location properties. For some reason however, my property (whose name is TitleMargin) is disabled in the property inspector. Does anybody know why this has happened and how I can get around this? I'[ve tried recreating the MarginStruc as a class instead of a structure but its still disabled???:mad:
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
The designer has no knowledge of the new type you have created. So it doen't no how to convert it to and from a string to b used in the designer. It looks like you are going to need to create a custom TypeConverter.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
The MarginStruc is also basically a Rectangle, so you can use this type for the TitleMargin property instead.
 

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
JohnH - That would make more sense. I'm really trying to get a class (or a structure) into the property inspector very much like the size and location properties do.
Vis781 - How would I do what you suggested?
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
VB.NET:
Public Class MrginStrucConverter
Inherits TypeConverter
 
Public Overloads Overrides Function CanConvertFrom(ByVal context As ITyoeDescriptorContext, ByVal sourceType As System.Type) As Boolean      
If (sourceType Is GetType(String)) Then            
Return True      
End If      
Return MyBase.CanConvertFrom(context, sourceType)
End Function
 
Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean   
If (destinationType Is GetType(InstanceDescriptor)) Then           
 Return True      
End If      
Return MyBase.CanConvertTo(context, destinationType)End Function

I have made a start for you above. You can also check out the RectangleConverter in the framework for some help.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,604
Location
Norway
Programming Experience
10+
If you use the Rectangle type you don't need a type converter, but I understood fredriko wanted to add any kind of structure to properties still.
 

lickuid

Active member
Joined
Nov 6, 2006
Messages
37
Programming Experience
Beginner
I'm not totally sure if I'll answer what you're asking, but I'll take a stab at it... I was looking for the same thing (I think) - Having the a variable of a custom control be visible in the .NET property inspector.. anyway, here's an example of what I did...
VB.NET:
Dim bH as integer = 6 'Bar Height
    Property barHeight() As String
        Get
            Return bH
        End Get
        Set(ByVal value As String)
            bH = value
        End Set
    End Property

The changes don't take place until after you've compiled your project. but once you do that, go back to your editor and add the control to your form (or whatever) and you'll see that property in the property inspector... I hope that helped
 

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
Lickuid, Cheers for that but its not quite qhat I was after.
I am hoping to, instead of passing a string (as in your example) pass a structure or a class. The problem I am having is that when I substitute the string for a structure the property is disabled in the property inspector.
I want to first create a structure like this:
VB.NET:
[COLOR=#000000]Public Structure NewSizeStruc[/COLOR]
[COLOR=#000000]   Public Height As Integer[/COLOR]
[COLOR=#000000]   Public Width As Integer[/COLOR]
[COLOR=#000000]End Structure[/COLOR]
Then pass the structure as a property like this...
VB.NET:
[COLOR=#000000]Private m_NewSize As NewSizeStruc[/COLOR]
[COLOR=#000000]Public Property NewSize() As NewSizeStruc[/COLOR]
[COLOR=#000000]   Get[/COLOR]
[COLOR=#000000]       Return m_NewSize[/COLOR]
[COLOR=#000000]   End Get[/COLOR]
[COLOR=#000000]   Set(ByVal Value As NewSizeStruc)[/COLOR]
[COLOR=#000000]       m_NewSize = Value[/COLOR]
[COLOR=#000000]       Me.invalidate()[/COLOR]
[COLOR=#000000]   End Set[/COLOR]
[COLOR=#000000]End Property[/COLOR]
I then want to be able to edit the class properties in the property inspector. For an example of what I am trying to achieve, look at the size and location properties of a windows control in the property inspector. In these examples you can expand size and modify the height and width values.
 

lickuid

Active member
Joined
Nov 6, 2006
Messages
37
Programming Experience
Beginner
Oh, I see... I tried what you did and it shows up in my property inspector. It won't show up when I open the designer for the .vb itself, only when I add the control to an existing object like a blank form for example. Also, it's not really collapsable like (i'm thinking) you want... Sorry I couldn't be of more help..
 
Top Bottom