Dear Telerik staff,
I am trying to insert a customized connection using the default
ConnectorTool into my RadDiagram. However, this seems near impossible because the
library does not expose a method to do that, as WPF does (https://www.telerik.com/forums/using-connection-tool-to-draw-custom-connection).
Consequently, I decided to create a custom tool, but it is not working. I need
a tool that provides the same functionality as the ConnectorTool, but that
employs a customized connection that contains its own visual traits and a set
of extra properties/variables.
My current code is as follows:
public
class
CustomTool : ToolBase, IMouseListener
{
public
CustomTool(
string
name) :
base
(name)
{
this
.Name = name;
}
IConnection currentConnection =
null
;
Point lastPoint;
public
virtual
bool
MouseDown(PointerArgs e)
{
try
{
if
(
this
.ToolService.ActiveTool !=
null
&&
this
.ToolService.ActiveTool.Name.Equals(
this
.Name))
{
HitTestService hitTestService = MainMenu.getDiagram().ServiceLocator.GetService<IHitTestService>()
as
HitTestService;
if
(
this
.currentConnection ==
null
)
{
this
.currentConnection =
new
CustomRadDiagramConnection(System.Drawing.Color.FromArgb(150, 45, 90),
"test"
);
if
(hitTestService.ShapeUnderMouse !=
null
)
{
this
.currentConnection.Source = hitTestService.ShapeUnderMouse;
}
this
.currentConnection.StartPoint = e.TransformedPoint;
this
.currentConnection.EndPoint =
this
.lastPoint = e.TransformedPoint;
this
.Graph.Items.Add((RadElement)
this
.currentConnection);
hitTestService =
null
;
return
true
;
}
}
}
catch
(NullReferenceException)
{
MessageBox.Show(
"Not working"
);
}
return
true
;
}
protected
override
void
OnActivated()
{
base
.OnActivated();
this
.lastPoint =
new
Point(0, 0);
this
.currentConnection =
null
;
}
protected
override
void
OnDeactivated()
{
base
.OnDeactivated();
this
.ToolService.ActivateTool(
"Pointer Tool"
);
this
.Graph.AddConnection(currentConnection);
//this.Graph.Items.Remove((RadElement)this.currentConnection);
this
.currentConnection =
null
;
}
public
virtual
bool
MouseMove(PointerArgs e)
{
if
(
this
.currentConnection !=
null
&&
this
.IsActive)
{
this
.currentConnection.EndPoint =
this
.lastPoint = e.TransformedPoint;
this
.currentConnection.Update();
return
true
;
}
return
false
;
}
public
virtual
bool
MouseUp(PointerArgs e)
{
HitTestService hitTestService = MainMenu.getDiagram().ServiceLocator.GetService<IHitTestService>()
as
HitTestService;
if
(IsActive)
{
if
(hitTestService.ShapeUnderMouse !=
null
)
{
this
.currentConnection.Target = hitTestService.ShapeUnderMouse;
}
this
.currentConnection.EndPoint =
this
.lastPoint;
this
.currentConnection.Update();
this
.DeactivateTool();
hitTestService =
null
;
return
true
;
}
return
false
;
}
public
bool
MouseDoubleClick(PointerArgs e)
{
return
false
;
}
}
Thank you