Dark Kai Posted February 9, 2004 Posted February 9, 2004 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 Quote
Leaders Iceplug Posted February 9, 2004 Leaders Posted February 9, 2004 Can't you add something like Public CSize As Size in your class? or Public Property CSize() As Size ... End Property ? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Dark Kai Posted February 10, 2004 Author Posted February 10, 2004 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 :) Quote
*Experts* Nerseus Posted February 10, 2004 *Experts* Posted February 10, 2004 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 Quote "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
Dark Kai Posted February 11, 2004 Author Posted February 11, 2004 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. Quote
*Experts* mutant Posted February 11, 2004 *Experts* Posted February 11, 2004 (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 February 11, 2004 by mutant Quote
Dark Kai Posted February 11, 2004 Author Posted February 11, 2004 hmmm I guess so I need to test this out first. Thanks a lot. Quote
Dark Kai Posted February 11, 2004 Author Posted February 11, 2004 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. Quote
*Experts* Nerseus Posted February 11, 2004 *Experts* Posted February 11, 2004 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 Quote "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
Procaine Posted February 11, 2004 Posted February 11, 2004 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). Quote
*Experts* Nerseus Posted February 13, 2004 *Experts* Posted February 13, 2004 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 Quote "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
Dark Kai Posted February 17, 2004 Author Posted February 17, 2004 Yah that's what i want. Procaine, do you have any examples ?? :) Quote
Procaine Posted February 17, 2004 Posted February 17, 2004 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. Quote
Dark Kai Posted February 18, 2004 Author Posted February 18, 2004 Oh ok....I'll try looking up for more info. If any1 out there have an example on this pls let me know. Thanks to all that had contributed in this thread. :p Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.