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

Diagram questions

Hi,

1) How can I change the default mouse behavior and cursor? BY default the mouse cursor should be normal pointer and simply perform a click on a node (currently it allows to move nodes). Then when holding down the ALT key I want the current behavior to allow moving nodes.

2) How can I determine the click position in the node when clicking a node, i.e. which pixel in the node has been clicked. I need this as I have several images on a node which are used like buttons, e.g. like in your expander sample the plus/minus symbol.

Regards,
Christian



2 Replies

CR Christian Rattat February 20, 2012 05:07 AM UTC

In addition to my previous post I understand that the current tool is the movetool which causes the cursor and behavior.

However I obviously have to have an active tool always and there seems to be no tool that simply does nothing than clicking.

How can I achieve this? Is there a sample for such a tool?

Regards,
Christian





AA Amsath Ali M Syncfusion Team February 27, 2012 08:56 AM UTC

Hi Christian,

Thanks for using Syncfusion products and sorry for the delay in getting back to you.

1. How can I change the default mouse behavior and cursor?


We suggest you to use the Diagram.Controller.ActiveTool’s ‘ActionCursor’ property to change active cursor of the tool. Please refer the below code snippet to achieve your requirement.

Here is the code:
[C#]
diagram1.Controller.ActiveTool.ActionCursor = Cursors.Hand;


2. How can I determine the click position in the node when clicking a node?
We suggest you to use the Diagram’s ‘MouseClick’ event and Diagram.Controller’s ‘ConvertToModelCooridinates’ methods to achieve your requirement. Please refer the below code snippet to achieve your requirement.

Here is the code:
[C#]
diagram1.MouseClick += new MouseEventHandler(diagram1_MouseClick);
void diagram1_MouseClick(object sender, MouseEventArgs e)
{
Point mousePoint = new Point(e.X, e.Y);
Point clickPoint = diagram1.Controller.ConvertToModelCoordinates(mousePoint);
Node node = diagram1.Controller.GetNodeUnderMouse(mousePoint) as Node;
if (node != null && node.ContainsPoint(clickPoint))
{
label2.Text = mousePoint.ToString();
}

}

3. How can I have an active tool always and there seems to be no tool that simply does nothing than clicking?

We have created a dummy tool which simply performs a click on a node and does nothing as per your requirement and you can press ‘Alt’ key to activate the default tool Please try the below code snippet to achieve your requirement

Here is the code:
[C#]
//Registering Dummy tool
DummyTool tool = new DummyTool(this.diagram1.Controller);
diagram1.Controller.RegisterTool(tool);

diagram1.MouseUp += new MouseEventHandler(diagram1_MouseUp);
diagram1.MouseMove += new MouseEventHandler(diagram1_MouseMove);
diagram1.KeyDown += new KeyEventHandler(diagram1_KeyDown);
diagram1.KeyUp += new KeyEventHandler(diagram1_KeyUp);
diagram1.MouseClick += new MouseEventHandler(diagram1_MouseClick);

void diagram1_MouseClick(object sender, MouseEventArgs e)
{
Point mousePoint = new Point(e.X, e.Y);
mousePoint = diagram1.Controller.ConvertFromModelToClientCoordinates(mousePoint);
Node node = diagram1.Controller.GetNodeUnderMouse(mousePoint) as Node;
if (node != null && node.ContainsPoint(mousePoint))
{
label2.Text = mousePoint.ToString();
}
if (node != null && diagram1.Controller.ActiveTool.Name == DummyTool.ToolName)
{
diagram1.View.SelectionList.Clear();
diagram1.View.SelectionList.Add(node);
}
else if(diagram1.Controller.ActiveTool.Name == DummyTool.ToolName)
{
diagram1.View.SelectionList.Clear();
}
}

void diagram1_MouseMove(object sender, MouseEventArgs e)
{
if (diagram1.Controller.ActiveTool.Name == "SelectTool" && checkBox1.Checked == true && !m_altPrsd)
{
//Activating Dummy tool in the mouse move
diagram1.Controller.ActivateTool(DummyTool.ToolName);
}
else if (diagram1.Controller.ActiveTool.Name == DummyTool.ToolName && checkBox1.Checked == false)
diagram1.Controller.DeactivateTool(diagram1.Controller.ActiveTool);
}

void diagram1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt == true && diagram1.Controller.ActiveTool.Name == DummyTool.ToolName)
{
//Activating Default tool when the Alt key is pressed.
diagram1.Controller.ActivateTool("SelectTool");
m_altPrsd = true;
}
}

void diagram1_MouseUp(object sender, MouseEventArgs e)
{
if (diagram1.Controller.ActiveTool.Name == "SelectTool" && checkBox1.Checked == true)
{
diagram1.Controller.ActivateTool(DummyTool.ToolName);
}
}

Here is the sample:
F10266663902740.zip


Please try the above sample and let us know if you have any queries.

Regards,
Amsath Ali. M



Loader.
Live Chat Icon For mobile
Up arrow icon