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


Thread ID:





21773 Nov 19,2004 07:42 PM UTC Nov 23,2004 06:25 PM UTC WinForms 2
Tags: Diagram
Truman Lackey
Asked On November 19, 2004 07:42 PM UTC

I have used GetPortAt before and it worked, but now I have either forgotten how I used it or for some unkown reason it has just stopped working! A sample application is attached. Does this function work for ports that belong to a symbol? Thanks Truman WindowsApplication3_5452.zip

Administrator [Syncfusion]
Replied On November 23, 2004 05:26 PM UTC

Hi Truman, A Port is an object anchored to a symbol that provides a location at which connections to other symbols can be made. 1) Here is a code snippet that demonstrates how you can get the location of the ports of the selected instance of MySymbol: private void PortLocation_Click(object sender, System.EventArgs e) { string portlocation = string.Empty; if (this.diagram1.SelectionList.Count == 1) { if(this.diagram1.SelectionList.First.GetType() == typeof(MySymbol)) { MySymbol mysym = (MySymbol)this.diagram1.SelectionList.First; foreach( Port port in mysym.Ports ) { portlocation+= port.Name + ":" + port.Location.ToString() + "\n\r"; } } } this.label1.Text = portlocation; } 2. 2) Here is a code snippet that updates the text of the label based on whether the user clicked on a port or did not (using the View''s GetPortAt() method: private void diagram1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { Port port = this.diagram1.View.GetPortAt(new Point(e.X,e.Y),0); if(port!=null) { if(port.GetType()==typeof(Syncfusion.Windows.Forms.Diagram.CirclePort)) this.label1.Text = ("You clicked on port:" + port.Name); } else this.label1.Text ="You did not click on a port"; } 3. And finally here is the custom Symbol class(MySymbol): public class MySymbol : Symbol { private Syncfusion.Windows.Forms.Diagram.Rectangle outerRect = null; private Ellipse innerEllipse = null; private CirclePort leftport; private CirclePort rightport; public MySymbol() { ////////////////////////////////////////////////////////////////// // Add child nodes to the symbol programmatically ////////////////////////////////////////////////////////////////// // Add an outer rectangle this.outerRect = new Syncfusion.Windows.Forms.Diagram.Rectangle(0, 0, 120, 80); this.outerRect.Name = "Rectangle"; this.outerRect.FillStyle.Type = Syncfusion.Windows.Forms.Diagram.FillStyle.FillType.LinearGradient; this.outerRect.FillStyle.Color = System.Drawing.Color.Gold; this.outerRect.FillStyle.GradientStartColor = System.Drawing.Color.Gray; this.outerRect.ShadowStyle.Visible = true; this.outerRect.LineStyle.LineWidth = 1; this.AppendChild(outerRect); // Add an inner ellipse this.innerEllipse = new Ellipse(10, 10, 100, 60); this.innerEllipse.Name = "Ellipse"; this.innerEllipse.LineStyle.LineWidth = 1; this.innerEllipse.ShadowStyle.Visible = false; this.AppendChild(innerEllipse); //Port locations leftport = new CirclePort(new PointF(0, this.Height / 2)); leftport.Name = "LeftPort"; rightport = new CirclePort(new PointF(this.Width, this.Height / 2)); rightport.Name = "RightPort"; //Append CirlePorts to MySymbol AppendChild(leftport); AppendChild(rightport); //Make CenterPort visible this.CenterPort.Visible = true; //Add Label Label lbl = this.AddLabel("My Symbol", BoxPosition.Center); lbl.BackgroundStyle.Color = Color.Transparent; } } Regards Arun

Administrator [Syncfusion]
Replied On November 23, 2004 06:25 PM UTC

Thanks for the explanation. I was flawed in thinking that I could just add a port to a diagram and then connect to it. The reason that I asked this is I was copying symbols from one diagram to another and the ports of the copied symbols were not linkable. It seems that when I cloned the original symbol that the collection of ports for the new symbol were getting their parents set to nothing. To fix this I had to go through the collection and set each port''s parent to the newly created symbol. Truman


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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