In this post, we will add attributes and methods to the component base class called Comp.cs. First add the following set of attributes using the "protected" access keyword so that subclasses have access:
// Protected property variables for Property Grid
protected String _orientation = "Series";
protected String _type;
protected String _name;
protected float _value;
protected Point _loc;
protected int[] _nodes;
protected int _width;
protected int _height;
Property Setters & Getters
The properties will be made available in the property grid but first property setters & getters are added:
// Orientation property with category attribute and description
attribute added
[CategoryAttribute("Location
Settings"), DescriptionAttribute("Orientation of the Component")]
public string Orientation
{
get
{
return _orientation;
}
set
{
_orientation =
value;
}
}
// Location property with category attribute and description
attribute added
[CategoryAttribute("Location
Settings"), DescriptionAttribute("Orientation of the Component")]
public Point Loc
{
get
{
return _loc;
}
set
{
_loc = value;
}
}
// Width property with category attribute and description
attribute added
[CategoryAttribute("Location
Settings"), DescriptionAttribute("Orientation of the Component")]
public int Width
{
get
{
return _width;
}
set
{
_width = value;
}
}
// Location property with category attribute and description
attribute added
[CategoryAttribute("Location
Settings"), DescriptionAttribute("Orientation of the Component")]
public int Height
{
get
{
return _height;
}
set
{
_height = value;
}
}
// Value property with category attribute and description
attribute added
[CategoryAttribute("Configuration
Settings"), DescriptionAttribute("Configuration of the Component")]
public float Value
{
get
{
return _value;
}
set
{
_value = value;
}
}
// Type property with category attribute and description attribute
added
[CategoryAttribute("Configuration
Settings"), DescriptionAttribute("Configuration of the Component")]
public string Type
{
get
{
return _type;
}
set
{
_type = value;
}
}
// Type property with category attribute and description attribute
added
[CategoryAttribute("Configuration
Settings"), DescriptionAttribute("Configuration of the Component")]
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
// Type property with category attribute and description attribute
added
[CategoryAttribute("Configuration
Settings"), DescriptionAttribute("Configuration of the Component")]
public int[] Nodes
{
get
{
return _nodes;
}
set
{
_nodes = value;
}
}
Virtual Methods
Polymophism will be used to allow components to draw themselves and to print debug messages to the output console. These methods are used in iterators such as a foreeach loop.
No comments:
Post a Comment