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.zipPlease try the above sample and let us know if you have any queries.
Regards,
Amsath Ali. M