I would create a triangle type figure and add it to RadDiagram control all this programmatically, can anyone help?
I'm using the class RadDiagramShape the problem is not that I put in the ElementShape property, I welcome your comments.
Regards.
14 Answers, 1 is accepted
Thank you for writing.
We do not have a predefined triangle shape, but you can easily create one. All you need to do is to inherit the ElementShape class and return the desired figure path:
public class Triangle : ElementShape{ public override GraphicsPath CreatePath(Rectangle bounds) { GraphicsPath path = new GraphicsPath(); Point top = new Point(bounds.X + bounds.Width / 2, bounds.Y); Point right = new Point(bounds.X + bounds.Width, bounds.Y + bounds.Height); Point left = new Point(bounds.X, bounds.Y + bounds.Height); path.AddPolygon(new Point[] { top, right, left }); return path; }}Then you can create the diagram shape like this:
private void radButton1_Click(object sender, EventArgs e){ RadDiagramShape shape1 = new RadDiagramShape() { Text = "", ElementShape = new Triangle(), BackColor = Color.LimeGreen }; shape1.Position = new Telerik.Windows.Diagrams.Core.Point(100, 100); radDiagram1.Items.Add(shape1);}Another example for this is available in he following article: Shapes.
Please let me know if there is something else I can help you with.
Dimitar
Telerik
How would we get a filled triangle (or other shape)?
Thanks.
The triangle is filled on my side (see attached image). What is the result on yours?
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
My code is very similar. The result is attached. Edited version of code below.
class UcDropdownDiagramShape : UcDiagramShape{ public UcDropdownDiagramShape(...) { base.ElementShape = new UcDropdownElementShape(...); base.ForeColor = ((UcElementShape)base.ElementShape).ForeColor; base.BackColor = ((UcElementShape)base.ElementShape).BackColor; }}
internal class UcDiagramShape : RadDiagramShape { LightVisualElement _label = new LightVisualElement();
LightVisualElement _labelRect = new LightVisualElement();... protected override void CreateChildElements() { base.CreateChildElements(); _label.Text = ""; _label.PositionOffset = new SizeF(0, 0); DiagramShapeElement.Children.Add(_label); DiagramShapeElement.Children.Add( _labelRect); }
class UcDropdownElementShape : UcFieldElementShape { public override GraphicsPath CreatePath(Rectangle bounds) { var path = base.CreatePath(bounds); int iTriWidth = 6; int iTriHeight = 4; int ypos = bounds.Y + (Element.ScrnH - iTriHeight) / 2 + 1; Point[] points = { new Point( bounds.X + Element.ScrnW - (iTriWidth + 5), ypos ), new Point( bounds.X + Element.ScrnW - 4, ypos), new Point( bounds.X + Element.ScrnW - 5 - iTriWidth / 2, ypos + iTriHeight)}; path.AddPolygon( points); return path; }... }
I left out
public class UcFieldElementShape : UcElementShape {...}
public abstract class UcElementShape : ElementShape { ... }Using the provided code I have created and attached a test project where you can see that the background is applied. Could you please check the project and let me know what I need to change in order to reproduce your case?
Perhaps it would be better to open a new support ticket and attach a modified version of the project where your case is reproduced.
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
Thanks. Just change this CreatePath method so that the shapes overlap. However, I notice also our stack traces are different when this CreatePath is being called. See below.
class UcDropdownElementShape : UcFieldElementShape{ public override GraphicsPath CreatePath(Rectangle bounds) { var path = base.CreatePath(bounds); int iTriWidth = 16; int iTriHeight = 14; int ypos = bounds.Y + (Element.ScrnH - iTriHeight) / 2 + 10; Point[] points = { new Point( bounds.X - 80 + Element.ScrnW - (iTriWidth + 5), ypos ), new Point( bounds.X - 80 + Element.ScrnW - 4, ypos), new Point( bounds.X - 80 + Element.ScrnW - 5 - iTriWidth / 2, ypos + iTriHeight)}; path.AddPolygon(points); //path.CloseFigure(); return path; }Mine:
> UCStudio.exe!UCStudio.UcDropdownElementShape.CreatePath(System.Drawing.Rectangle bounds) Line 32 C# Telerik.WinControls.RadDiagram.dll!Telerik.WinControls.UI.Diagrams.UIElement.HitTest(System.Drawing.Point point) Unknown Telerik.WinControls.dll!Telerik.WinControls.RadElementTree.GetElementAtPoint(Telerik.WinControls.RadElement parent, System.Drawing.Point point, System.Collections.Generic.List<Telerik.WinControls.RadElement> foundElements, System.Predicate<Telerik.WinControls.RadElement> predicate) Unknown Telerik.WinControls.dll!Telerik.WinControls.RadElementTree.GetElementAtPoint(Telerik.WinControls.RadElement parent, System.Drawing.Point point, System.Collections.Generic.List<Telerik.WinControls.RadElement> foundElements, System.Predicate<Telerik.WinControls.RadElement> predicate) Unknown
Yours:
> _957043.exe!_957043.UcDropdownElementShape.CreatePath(System.Drawing.Rectangle bounds) Line 69 C#Telerik.WinControls.dll!Telerik.WinControls.ElementShape.CreatePath(System.Drawing.RectangleF bounds) UnknownTelerik.WinControls.dll!Telerik.WinControls.Primitives.FillPrimitiveImpl.PaintFill(Telerik.WinControls.Paint.IGraphics graphics, float angle, System.Drawing.SizeF scale, System.Drawing.RectangleF paintRect) UnknownTelerik.WinControls.UI.dll!Telerik.WinControls.UI.UIItemBase.PaintFill(Telerik.WinControls.Paint.IGraphics graphics, float angle, System.Drawing.SizeF scale, System.Drawing.RectangleF prefferedRectangle) Unknown
Also, I need the shapes to be different fore/back colors. See attached.
PS: Additional to the post above, it seems the overlaid triangle shape is causing an 'opening' in the polygon it overlays, so the background (e.g. grid or other shape) is showing through.
The Element property is not available on my side. Could you please update my test project so it reproduces this and attach it to a new support thread. This will allow me to properly investigate the case and provide you with a solution.
Thank you in advance for your patience and cooperation.
Regards,
Dimitar
Progress Telerik
These were just some fixed values. Thanks.
public static class Element
{
public static int ScrnH = 15;
public static int ScrnW = 150;
}
This creates a small filled tringle. I have attached an updated version of my test project.
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik
Replace the commented out line, with the one below it. Everything else is the same. Thanks.
public override GraphicsPath CreatePath(Rectangle bounds){ //var path = new GraphicsPath(FillMode.Alternate); var path = base.CreatePath(bounds);If the parent path is used the triangle will be excluded from the shape since it is within the shape bounds, this is the expected result. How do you expect this shape to look?
I am looking forward to your reply.
Dimitar
Progress Telerik
hi
i want show(×).
