We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom Property Editor

Hi,

I am looking for a way to custom my property editor. If I show the properties of a line, I only want to show line style part and hide the others. Could you help me?

Thanks in advanced


4 Replies

PM Pandi Murugan A Syncfusion Team January 6, 2011 07:44 AM UTC

Hi blanca,

Thanks for using Syncfusion products.

We suggest you to use Custom TypeConverter for Line to achieve your requirement. We have created a custom linetool with a custom line and have applied custom TypeConverter to the custom line as below.


//Custom Line class

[TypeConverter(typeof(LineTypeConverter))]
class MyLine:Line
{
public MyLine()
: base()
{
}
public MyLine(PointF ptStart, PointF ptEnd)
: base(ptStart, ptEnd)
{
}
}

//Custom LineTool

class MyLineTool:LineTool
{
internal static string ToolName = "MyLineTool";
public MyLineTool(DiagramController controller)
: base(controller)
{
this.Name = ToolName;
}
protected override Node CreateNode(System.Drawing.PointF ptStart, System.Drawing.PointF ptEnd)
{
return new MyLine(ptStart, ptEnd);
}
}

//Custom TypeConverter

class LineTypeConverter:TypeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
return base.ConvertTo(context, culture, value, destinationType);
}

public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
Attribute[] attrs = new Attribute[]
{
new BrowsableAttribute(true)
};

PropertyDescriptor[] props = null;
Type type = value.GetType();
switch (type.Name)
{
case "MyLine":
props = new PropertyDescriptor[1];
//Show LineStyle property Only
props[0] = TypeDescriptor.CreateProperty(typeof(MyLine), "LineStyle", typeof(LineStyle), attrs);
break;
default:
break;

}
return new PropertyDescriptorCollection(props);
}
}



For your convenient, we have prepared a simple sample to demonstrate this and the same can be downloaded from the below link.

Sample385445385.zip

Kindly try the above sample and let me know if this helps.

Regards,
Pandi Murugan A




BC Blanca Calderon January 10, 2011 08:57 AM UTC

But If I want to show only LineWidth of the LineStyle collection and hide the others what do I have to do? And not only this, I want to show the LineWidth and MeasureUnits of General Node.

Thanks in advanced.

Best regards

Blanca



BC Blanca Calderon January 10, 2011 10:22 AM UTC

how do I refer to bounds collections, size?

Again thanks.



PM Pandi Murugan A Syncfusion Team January 11, 2011 12:07 PM UTC

Hi Blanca,

Thanks for the update.
1. But If I want to show only LineWidth of the LineStyle collection and hide the others what do I have to do? And not only this, I want to show the LineWidth and MeasureUnits of General Node.

We regret to let you know that you cannot apply type converter to a Node in general. We suggest you to create custom shapes/connectors and apply type converter to them separately in order to achieve your requirement. Since LineStyle property is read only , you cannot set LineStyle which has custom type converter to a node in order to filter its LineWidth.

2. how do I refer to bounds collections, size?
We suggest you to use BoundingRectangle property of a Node to get its bounds and size. Please refer the below code snippet.

[C#]
Syncfusion.Windows.Forms.Diagram.Rectangle rect = new Syncfusion.Windows.Forms.Diagram.Rectangle(10, 10, 100, 100);
SizeF nodeSize = rect.BoundingRectangle.Size;
PointF loaction = rect.BoundingRectangle.Location;
float top = rect.BoundingRectangle.Top;
float bottom = rect.BoundingRectangle.Bottom;
float right = rect.BoundingRectangle.Right;
float left = rect.BoundingRectangle.Left;

Please let me know if you have any concerns.

Regards,
Pandi Murugan A


Loader.
Live Chat Icon For mobile
Up arrow icon