Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi every1, need some help here with properties.

I'm trying to group my properties like the property "Size" in a form which consist of width and height.

Thanks in advance

  • Leaders
Posted

Can't you add something like

Public CSize As Size

in your class?

or

Public Property CSize() As Size

...

End Property

?

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted
Oh well, sure I can do that but I my property is not of type �Size�, it's just an example heheheheheh I�m doing something that needs the user to input 3 double value which are XAngle, YAngle and ZAngle. Sorry for the confusion :)
  • *Experts*
Posted

You have to make your own struct or class and expose your property as one of that type.

 

Say your "property" is "Vector" with 3 subproperties "X", "Y" and "Z":

public struct Vector
{
   public double X;
   public double Y;
   public double Z;
}

public class MyClass
{
   public Vector Vector;
}

// Farther down in code:
MyClass c = new MyClass();
c.Vector.X = 1.0;
c.Vector.Y = 2.0;
c.Vector.Z = 3.0;

 

NOTE: In C# you can name a field the same as a type, as shown with "public Vector Vector" above. This is semi-common practice when you don't want to extend the Vector class but really just use it as a grouping mechanism for other properties. You can't do this in VB.NET as far as I know as it won't let you declare a variable like that (same name as the type). You might be able to name the struct "_Vector" or something similar, then name your property Vector.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
I've tried that already, but it's just a blank property at the "property manager". Sort of readonly property and there is no + next to it for me to expend the property.
  • *Experts*
Posted (edited)

Are you looking for something like this? Im not entirely sure what you need.

'define some class
Public Class MyOwnProperty
    'declare some vars
    private _width as Integer
    private _height as integer
    'now declare properties
    Public Property Width As Integer
    Get
         return _width
    End Get
    Set(ByVal Value As Integer)
         _width = Value
    End Set
    End Property
    Public Property Height As Integer
    Get
         return _height
    End Get
    Set(ByVal Value As Integer)
         _height = Value
    End Set
    End Property
End Class

'and now use this class as a readonly property
Public Class ClassToUseProperty
    'declare the previous class that was made
    private _myproperty As New MyOwnProperty
    'And use the object as a read-only property
    Public ReadOnly Property TheProperty As MyOwnProperty
    Get
          return _myproperty
    End Get
    End Property
End Class

Edited by mutant
Posted
I tested the codes and it's not working. well the results are the same as a readonly property and i can't access the Width and Height in the MyOwnProperty class.
  • *Experts*
Posted

Ah, you need this as a property on a Control, so that it shows up in the Properties window. That's a bit different :)

 

Unfortunately, I don't know the right decoration to add to get that to work for a custom class. You might try divil as he's the resident Custom Control guru. Or try looking in the MSDN help custom attributes/decorations (things like [WebMethod] that you put before a function/property to tell the compiler to add extra info).

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Public properties, readonly or not, will show up in the properties window of a custom control without any attributes.

 

Some of the attributes I use in this case are DescriptionAttribute (sets the description that's shown property window), CategoryAttribute (which category it comes under) and defaultvalueAttribute (when the property = DefaultValueAttribute, it's non-bold in the property window; <> default value and it's shown as bold).

  • *Experts*
Posted

I think he wants a custom object to show up in the properties window, complete with a little "+" to allow expanding and showing the variables of the subtype. Will that happen automatically?

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Sorry, no, I haven't done this before, and I think I remember having trouble with it in the past.

 

If I get some time I'll take a look in to it and get a solution.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...