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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Use custom Tools

Thread ID:

Created:

Updated:

Platform:

Replies:

89055 Aug 17,2009 04:10 PM UTC Sep 10,2009 07:31 AM UTC Windows Forms 8
loading
Tags: Diagram
Stephane Guerillot
Asked On August 17, 2009 04:10 PM UTC

Hello,

Things are a little harder than I thought.

I would like to create two custom tools. The first one would be used to override the SelectTool, in order to change the mouse icon, check the multiple selection before drag&drop, and other features.
I've tried to create a new class with
public class CustomSelectMove : Tool
but it didn't worked well (the default SelectTool is activated on the first mouseClick event).

The best result I got is when I use this class,
public class CustomSelectMove : SelectTool
even if it's not a good way to develop.

The second custom Tool, inheriting from OrthogonalConnectorTool, would be activated when the user clicks on a ConnectionPoint. I tried to activate this tool in the CustomSelectTool, but it didn't work.

Could you help me ? I would soon create a simple program in order to give you a more precise example of what I want to do.

Thanks.

Stephane Guerillot
Replied On August 18, 2009 09:35 AM UTC

Well, I've extracted a simple version of my code, showing what I tried to realise.

public class Main
{
private void initializeDiagram(Syncfusion.Windows.Forms.Diagram.Controls.Diagram diagram)
{
(...)
diagram.Controller.RegisterTool(new CustomSelectTool(diagram.Controller));
diagram.Controller.RegisterTool(new CustomLinkTool(diagram.Controller));
diagram.Controller.ActivateTool("CustomSelectTool");
}

private void Button_Click(object sender, EventArgs e)
{
Syncfusion.Windows.Forms.Diagram.Controls.Diagram diagram = this.GetDiagram();
diagram.Controller.ActivateTool("CustomLinkTool");
}
}
When initializing the Diagram, I register the two custom tools, and activate the first one. In all the examples I saw, the LinkTool is activated with an event on a button, like with Button_Click(). But I want to activate the LinkTool when clicking on the diagram.

public class CustomSelectTool : SelectTool
{
public CustomSelectTool(DiagramController ctrl) : base(ctrl, Syncfusion.Windows.Forms.Diagram.SelectMode.Intersecting)
{
this.Name = "CustomSelectTool";
this.SingleActionTool = false;
}

public override Tool ProcessMouseMove(MouseEvents e)
{
Tool tool = base.ProcessMouseMove(e);
(...)
return tool;
}
public override Tool ProcessMouseUp(MouseEvents e)
{
Tool tool = base.ProcessMouseUp(e);
(...)
return tool;
}
public override Tool ProcessMouseDown(MouseEvents e)
{
Tool tool = base.ProcessMouseDown(e);
(...)
if(CheckIfPositionIsCorrect(e) == true)
{
this.Controller.ActivateTool("CustomLinkTool");
this.Controller.ActiveTool.ProcessMouseDown(e);
}
return tool;
}
}
This is the Tool which I want to be activated permanently. The SelectTool methods are overriden, and I tried to activate the second tool on a MouseDown event at the good position.

public class CustomLinkTool: OrthogonalConnectorTool
{
private OrthogonalConnector connector;

public CustomLinkTool(DiagramController ctrl) : base(ctrl, Syncfusion.Windows.Forms.Diagram.SelectMode.Intersecting)
{
this.Name = "CustomLinkTool";
connector = new OrthogonalConnector(new PointF(), new PointF(0, 1));
}

protected override Node CreateNode(PointF ptStart, PointF ptEnd)
{
return connector;
}

public override Tool ProcessMouseMove(MouseEvents e)
{
Tool tool = base.ProcessMouseMove(e);
(...)
return tool;
}
public override Tool ProcessMouseDown(MouseEvents e)
{
Tool tool = base.ProcessMouseDown(e);
(...)
return tool;
}
public override Tool ProcessMouseUp(MouseEvents e)
{
Tool tool = base.ProcessMouseUp(e);
(...)
this.Controller.ActivateTool("CustomSelectTool");
this.DeactivateTool();
return tool;
}
}
This is the second Tool, which has to draw the links. ProcessMouseMove, ProcessMouseDown and ProcessMouseUp are overriden, and the tool deactivates itself when the mouse button is released.

I think the way I chosse is wrong, that's why it didn't work. But I don't know how to do what I want with another way.

Thanks a lot for your help.

Gowri Manohari D [Syncfusion]
Replied On August 19, 2009 01:23 PM UTC

Hi Stephane,

Thank you for choosing Syncfusion products.

You have created two custom tools one is CustomSelectTool and another one CustomLinkTool. You want to activate the CustomLinkTool in CustomSelectTool. Let me know whether the above point is same as your requirement. If it is not means please provide some more details about your requirement.

Regards,
Gowri

Stephane Guerillot
Replied On August 19, 2009 02:09 PM UTC

That's exacly what I am trying to do. In my mind, the two custom Tools will work together, the first one (CustomSelectTool) launching the second one (CustomOrthogonalLinkTool) when a MouseDown is detected and if the mouse is on a connection point.

Then, after drawing a link between two connection points (and, more generally, after a MouseUp event), CustomOrthogonalLinkTool will deactivate itself, and let CustomSelectTool continue the job.

I've met two different problems during my tests :
- I can't activate CustomOrthogonalLinkTool during a MouseDown event controles by CustomSelectTool. But it works well if a click on a button.

- After drawing a link, the original SelectTool remains active. It seems that CustomOrthogonalLinkTool didn't succeed in activating CustomSelectTool.

I don't know if the Tool object is the good one for what I am trying to do, but it's the best I found.

Thanks for your help ;)

Stephane Guerillot
Replied On August 20, 2009 08:37 AM UTC

Well, I've understood my mistake.

The tools I have overloaded didn't have the same name as the original ones. This is corrected and works well.

But I have another question : is it possible to overload the MoveTool ? It isn't registered with the others, and created only when it is needed by the UITool class (and inheritants).

Stephane Guerillot
Replied On August 21, 2009 03:01 PM UTC

I've done many mistakes in my initial question, interverting OrthogonalLinkTool and OrthogonalConnectorTool, not using MoveTool, and renaming all my new tools with a "Custom". Cute names, but it didn't work ;).

Well, I hope this version will be clearer.

I got a diagram (SyncFusion.Windows.Forms.Diagram.Control.Diagram), which had nodes (custom class, inheriting from Node) inside. These nodes are composed by a body, a Rectangle, and connection points (inheriting from ConnectionPoint).

I would like, when the mouse is on a ConnectionPoint, to draw a link by clicking on the ConnectionPoint, and releasing the button on the second ConnectionPoint.
To do this, I first create my own class inheriting from SelectTool (it seems to be the default tool in the diagram), and registered it in the ToolList (unregister the first one, and register the customized SelectTool). And I did the same with the OrthogonalConnectorTool.
Then, in the ProcessMouseDown of my own SelectTool, I try to do
this.Controller.ActivateTool("OrthogonalConnectorTool");
this.Controller.ActiveTool.ProcessMouseDown(evtArgs);


But it didn't work. The ActivateTool function returns true, but the Controller keeps SelectTool as the activated Tool, provocating a memory overflow.

How can I fix this ?

Thanks again for your help and for your work.

PS : I go on holliday next week, so I will ask some questions in different topics. Sorry for spamming this forum.

Gowri Manohari D [Syncfusion]
Replied On August 26, 2009 07:24 AM UTC

Hi Stephane,

Sorry for the delay response. Please replace the below lines of code in the corresponding place and let me know it solves your issue.

Please replace the below event ProcessMouseDown in CustomSelectTool class

public override Tool ProcessMouseDown(MouseEvents e)
{
if(CheckIfPositionIsCorrect(e) == true)
{
this.Controller.ActivateTool("CustomLinkTool");
this.Controller.ActiveTool.ProcessMouseDown(e);
Tool tool=(Tool) this.Controller.ActiveTool
}
return tool;
}

Please replace below event ProcessMouseUp in CustomLinkTool class

public override Tool ProcessMouseUp(MouseEvents e)
{
this.Controller.ActivateTool("CustomSelectTool");
this.DeactivateTool();
Tool tool=(Tool) this.Controller.ActiveTool
return tool;
}


Regards,
Gowri

Stephane Guerillot
Replied On September 9, 2009 04:05 PM UTC

It works well now, thanks ;)

Gowri Manohari D [Syncfusion]
Replied On September 10, 2009 07:31 AM UTC

Hi Stephane,

Thank you for your update.

Regards,
Gowri

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;