Connetti forme
Contents
[
Hide
]
Connetti forme
Questa sezione spiega come collegare due forme utilizzando Aspose.Diagram for Java.
Connetti forme
IlconnectShapesViaConnector method connect two shapes via a connector in the Pagina classe.
Il codice seguente mostra come:
- Crea uno diagram dallo stencil.
- Aggiungi due rettangoli alla pagina.
- Aggiungi una forma connettore alla pagina.
- Connetti i due rettangoli con il connettore usando connectShapesViaConnector mothod
- salvo diagram
Esempio di programmazione Connect Shapes
Utilizzare il codice seguente per connettere le forme utilizzando Aspose.Diagram for Java.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConnectShapes.class); | |
String stencil = dataDir + "Basic Shapes.vss"; | |
// create a diagram from stencil | |
Diagram diagram = new Diagram(stencil); | |
String connectorMaster = "Dynamic connector"; | |
String rectangleMaster = "Rectangle"; | |
// add two rectangles to page 0 | |
long rectangle1 = diagram.addShape(2, 2, rectangleMaster, 0); | |
long rectangle2 = diagram.addShape(2, 4, rectangleMaster, 0); | |
// add a connector to page 0 | |
Shape connector1 = new Shape(); | |
long connecter1Id = diagram.addShape(connector1, connectorMaster, 0); | |
// connect the two rectangles with the connector | |
diagram.getPages().get(0).connectShapesViaConnector(rectangle1, ConnectionPointPlace.RIGHT, rectangle2, ConnectionPointPlace.BOTTOM, connecter1Id); | |
// If the connection of shapes has name, we also could use connection name to connect like below | |
//diagram.getPages().get(0).connectShapesViaConnector(shape1, "Port7", shape2, "Port21", connecter1Id); | |
// The code line above is equal to the below two lines | |
//diagram.getPages().get(0).glueShapeToConnectorBeginX(shape1, "Port7", connecter1Id); | |
//diagram.getPages().get(0).glueShapeToConnectorEndX(shape2, "Port21", connecter1Id); | |
// Save diagram | |
diagram.save(dataDir + "ConnectShapes_out.vsdx", SaveFileFormat.VSDX); |
Risultato |
---|
![]() |