How to custom a diagramtoolbox item?

6 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    26 posts
    Member since:
    Jan 2016

    Posted 01 Apr Link to this post

    Hi, I want to custom a diagramtoolbox item, how to do it with UI for WinForms?

    waiting for answer, thanks

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 04 Apr Link to this post

    Hello Jonathan,

    Thank you for writing.

    RadDiagramToolbox is a derivative of RadListView. Hence, if you need to add a custom item to it, please refer to the following code snippet:
    public Form1()
    {
        InitializeComponent();
        DiagramListViewDataItem item;
        item = new DiagramListViewDataItem() { Key = "My shape" };
        ElementShape shape = new RoundRectShape(15);
        item.Shape = shape;
        item.Group = this.radDiagramToolbox1.Groups[0];
        this.radDiagramToolbox1.Items.Add(item);
    }

    If it is not the exact requirement, please specify in details what is the exact goal that you are trying to achieve.

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jonathan
    Jonathan avatar
    26 posts
    Member since:
    Jan 2016

    Posted 04 Apr in reply to Dess Link to this post

    Thanks for your reply~~

    I want to custom some shapes like Ellipse,RoundRect that have no FillColor. Then, I can drag for use directly. Please see attachment.

  5. Jonathan
    Jonathan avatar
    26 posts
    Member since:
    Jan 2016

    Posted 05 Apr Link to this post

    I also want to custom the color of the borders and so on. waiting for you, thanks~~
  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 06 Apr Link to this post

    Hello Jonathan,

    Thank you for writing back. 

    Here is demonstrated a sample code snippet how to customize the shape color and its thickness. Note that you can introduce any changes to the visual items in the RadDiagramToolbox by using the VisualItemFormatting which is inherited from RadListview.
    public Form1()
    {
        InitializeComponent();
     
        this.radDiagramToolbox1.VisualItemFormatting += radDiagramToolbox1_VisualItemFormatting;
        DiagramListViewDataItem item;
        item = new DiagramListViewDataItem() { Key = "My shape" };
        DonutShape shape = new DonutShape();
        shape.Thickness = 2;
        item.Shape = shape;
        item.Group = this.radDiagramToolbox1.Groups[0];
        this.radDiagramToolbox1.Items.Add(item);
    }
     
    private void radDiagramToolbox1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
    {
        DiagramListViewDataItem dataItem = e.VisualItem.Data as DiagramListViewDataItem;
        if (dataItem != null)
        {
            DiagramListViewVisualItem el = e.VisualItem as DiagramListViewVisualItem;
            if (((DiagramListViewDataItem)e.VisualItem.Data).Key.ToString() == "My shape")
            {
                el.ShapeElement.BackColor = Color.Red;
            }
            else
            {
                el.ShapeElement.BackColor = Color.FromArgb(37, 160, 218);
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  7. Jonathan
    Jonathan avatar
    26 posts
    Member since:
    Jan 2016

    Posted 19 Apr in reply to Dess Link to this post

    Thank you Dess!  Sorry reply so late. I think I got it. If any question else, I'll ask you.

    Best regards!

Back to Top
UI for WinForms is Visual Studio 2017 Ready