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

GetPortAt

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

2 Replies

AD Administrator Syncfusion Team 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


AD Administrator Syncfusion Team 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

Loader.
Up arrow icon