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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Position labels on the Symbol

Thread ID:

Created:

Updated:

Platform:

Replies:

70349 Dec 7,2007 11:45 PM UTC Dec 27,2007 11:18 PM UTC WinForms 8
loading
Tags: Diagram
Administrator [Syncfusion]
Asked On December 7, 2007 11:45 PM UTC

Hello there,
I have a symbol with multiple ports that are position in one column evenly dispersed. Next to each port, lets say on the left, must be a label associated with it. How can I position the label so it would stay next to its port?
In addition, when symbol is resized should I reposition the labels?
I'm using Essential Studio 4.4.0.46

Thanks for your help



Administrator [Syncfusion]
Replied On December 8, 2007 04:01 AM UTC

I've got it to the point where labels are positioned correctly at the begining. As soon as symbol is resized the ports' locations on the screen changed, but the labels seems to stay unchanged. I tried following code (in the mySymbol class) to make labels follow their ports but it didn't work. The offset/location of a port doesn't seems to change on resize. How can I do this?

Thanks for your help.

protected override void OnBoundsChanged(BoundsEventArgs evtArgs)
{
float portXoffset, portYoffset;
for (int i = 0; i < Ports.Count; i++)
{
//Create port...
CirclePort port = (CirclePort)Ports[i].Clone();
portXoffset = port.Location.X;

SymbolLabel lbl = (SymbolLabel)Labels[port.Name];
lbl.OffsetX = bundleType == BundleType.RxBundle ? portXoffset + lbl.Width : portXoffset - lbl.Width;
lbl.OffsetY = port.Location.Y;
}
base.OnBoundsChanged(evtArgs);
}



Golda Rebecal [Syncfusion]
Replied On December 11, 2007 09:59 AM UTC

Hi,

The port location is not changed in the OnBoundsChanged event of Symbol since the port location is assigned only after the symbol bounds are changed.You can achieve your requirement by handling the BoundsChanged event of the Diagram.

Here is the code snippet:

private void diagram1_BoundsChanged(object sender, BoundsEventArgs evtArgs)
{
SymbolLabel lbl1 = rectangle.GetChildByName("lbl1") as SymbolLabel;
SymbolLabel lbl2 = rectangle.GetChildByName("lbl2") as SymbolLabel;
SymbolLabel lbl3 = rectangle.GetChildByName("lbl3") as SymbolLabel;
CirclePort port1 = rectangle.GetChildByName("port1") as CirclePort;
CirclePort port2 = rectangle.GetChildByName("port2") as CirclePort;
CirclePort port3 = rectangle.GetChildByName("port3") as CirclePort;
lbl1.OffsetY = rectangle.Height/2 + (rectangle.Height/2)/2 ;
lbl2.OffsetY = rectangle.Height/2;
lbl3.OffsetY = rectangle.Height/2 - (rectangle.Height/2)/2 ;
}


Kindly let me know if this helps you.

We appreciate your interest in Syncfusion products.

Best regards,
Golda


Administrator [Syncfusion]
Replied On December 11, 2007 11:57 PM UTC

Thank you Golda, it works now.

Here is another question if I may.
I'm trying to validate created link. I found the following code on this forum. The below method should be called twice and if condition is true the link should be canceled. In reality, the method is called four times where the logic to cancel the link is executed once, but link is still created. It looks like I'm subscribed to this event twice or it get called recursively. Any idea?

Thanks



private void diagram1_ConnectionsChanging(object sender, ConnectionCollectionEventArgs evtArgs)
{
if ((evtArgs.ChangeType == CollectionExChangeType.Insert) && (evtArgs.Connection != null))
{
Connection newconn = evtArgs.Connection;
Link newlink = null;
if (newconn.SourcePort is LinkPort)
newlink = newconn.SourcePort.Container as Link;
else if (newconn.TargetPort is LinkPort)
newlink = newconn.TargetPort.Container as Link;

if ((newlink != null) && (newlink.FromNode != null) && (newlink.ToNode != null))
{
//Symbols involved...
DiagSymbol oneSym = newlink.FromNode as DiagSymbol;
DiagSymbol anotherSym = newlink.ToNode as DiagSymbol;
if (oneSym.bundleType == anotherSym.bundleType)
{
evtArgs.Cancel = true;
RemoveNodesCmd removecmd = new RemoveNodesCmd();
removecmd.Nodes.Add(newlink);
this.diagram1.Controller.ExecuteCommand(removecmd);
}
}
}
}


Administrator [Syncfusion]
Replied On December 12, 2007 07:03 PM UTC

Here's the link where I found the example:
http://www.syncfusion.com/support/kb/diagram/Default.aspx?ToDo=view&questId=34&catId=3

I did a little experiment and copied this code into Cool Links diagram example. It behaves exactly the same way as in my application (as I described in the previous post) and the link cancel command doesn't seems to work.
Is it a bug and is there a work around?
As I mentioned before I'm running Essential Studio V 4.4.0.46

Please advise


Golda Rebecal [Syncfusion]
Replied On December 14, 2007 11:16 AM UTC

Hi,

This is a known issue in older version. We have refactored the code for Diagram in our latest release(Essential Studio 2008 Volume 1(v6.1.0.34)). You can verify your needs by downloading it from the following link:

http://www.syncfusion.com/support/forums/message.aspx?&MessageID=70234

Please try this and let me know if you have any questions.

Best regards,
Golda




Administrator [Syncfusion]
Replied On December 14, 2007 06:44 PM UTC

Hi Golda,
Thanks for your help.
I kind of find a solution to this problem, at least it looks like the solution visually. It removes the link. Below you'll find a modified version of the function that I sent you before. Could you tell me if is okay to do it this way. Please see the comments in the code.

private void diagram1_Model_ConnectionsChanging(object sender, ConnectionCollectionEventArgs evtArgs)
{
if ((evtArgs.ChangeType == CollectionExChangeType.Insert) && (evtArgs.Connection != null))
{
Connection newconn = evtArgs.Connection;
Link newlink = null;
if (newconn.SourcePort is LinkPort)
newlink = newconn.SourcePort.Container as Link;
else if (newconn.TargetPort is LinkPort)
newlink = newconn.TargetPort.Container as Link;

if ((newlink != null) && (newlink.FromNode != null) && (newlink.ToNode != null))
{
//Symbols involved...
DiagSymbol oneSym = newlink.FromNode as DiagSymbol;
DiagSymbol anotherSym = newlink.ToNode as DiagSymbol;
if (oneSym.bundleType == anotherSym.bundleType)
{
//1. THE FOLLOWING SEEMS TO WORK
evtArgs.Cancel = true;
diagram1.Model.RemoveChild(diagram1.Model.GetChildIndex(newlink));
//2. WOULD THE FOLLOWING BE REDUNDANT TO USE WITH THE CODE IN SECTION 1
RemoveNodesCmd removecmd = new RemoveNodesCmd();
removecmd.Nodes.Add(newlink);
removecmd.Do(diagram1);
//3. WHAT'S THE DIFFERENCE BETWEEN EXECUTING command.Do() vs. diagram.Controller.ExecuteCommand()
//this.diagram1.Controller.ExecuteCommand(removecmd);
diagram1.Refresh();
}
}
}
}



Please advise and thanks for your help.



Administrator [Syncfusion]
Replied On December 26, 2007 03:45 PM UTC

Hello there,
Can somebody advise me with the example from my previous email in this thread?

Thanks for your help.

Regards, Leo


J.Nagarajan [Syncfusion]
Replied On December 27, 2007 11:18 PM UTC

Hi LR,

Sorry for the delay in getting back to you. If your intention is to remove the link connected to a node being deleted then you have to use RemoveNodeCmd in ConnectionsChanging event.

But the diagram history manager now does not allow another action (removing a link) to proceed when an action is pending (the add link action is considered complete only after the event handler returns). That is why the RemoveNodesCmd action is not executed. Currently you need to call RemoveNodeCommand after the execution of ConnectionsChanging event. You can use the following code to remove the link in Connectionchanging event.

private void diagram1_Model_ConnectionsChanging(object sender, ConnectionCollectionEventArgs evtArgs)
{
evtArgs.Cancel = true;
diagram1.Model.RemoveChild(diagram1.Model.GetChildIndex(newlink));
}

diagram.Controller.ExecuteCommand() is used to execute the diagram commands like InsertNodeCommand,RemoveCommand,LinkCommand,MoveCommand etc. When diagram.Controller.ExecuteCommand() returns true value, it automatically calls command.Do() method. In the command.Do() method, the execution process will be done for the corresponding command.

Please let me know if you have any other questions.

Regards,
Nagaraj


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

;