To draw a Visio diagram through. NET, you would first import the Visio COM component, which is to add the Visio COM component to the reference, and then you can write the code drawing after the import is played. Put a simple sample code to make it easy to understand:
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.text;using system.windows.forms;using Visio = microsoft.office.interop.visio;using AXVISOCX = axmicrosoft.office.interop.visocx;//using system.web.ui.webcontrols;using Cell = Microsoft.office.interop.visio.cell;namespace visiotest1{public partial class Form2:form {public Form2 () {InitializeComponent (); } private static void ConnectShapes (Visio.Shape shape1, Visio.Shape shape2, Visio.Shape connector) { Get the cell from the source side of the connector cell Beginxcell = CONNECTOR.GET_CELLSSRC ( (short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXForm1D, (short) Visio.vis Cellindices.vis1dbeginx); Glue the source side of the connector to the first shape Beginxcell.glueto (SHAPE1.GET_CELLSSRC ( (short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXFormOut, (short) VISIO.VI Scellindices.visxformpinx)); Get the cell from the destination side of the connector cell Endxcell = CONNECTOR.GET_CELLSSRC ( Short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXForm1D, (short) Vis Io. VISCELLINDICES.VIS1DENDX); Glue the destination side of the connector to the second shape Endxcell.glueto (SHAPE2.GET_CELLSSRC ( (short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXFormOut, (short) VISIO.VI Scellindices.visxformpinx)); } private void Form2_load (object sender, EventArgs e) {axDrawingControl1.Window.Zoom = 0.5; AxDrawingControl1.Window.ShowScrollBars = (short) Visio.VisScrollbarStates.visScrollBarBoth; Axdrawingcontrol1.wiNdow. showrulers = 0; AxDrawingControl1.Window.BackgroundColor = (UINT) colortranslator.toole (color.red); AxDrawingControl1.Window.BackgroundColorGradient = (UINT) colortranslator.toole (color.red); AxDrawingControl1.Window.ZoomBehavior = Visio.VisZoomBehavior.visZoomVisioExact; Visio.page currentpage = axdrawingcontrol1.document.pages[1]; Visio.Document currentstencil = axDrawingControl1.Document.Application.Documents.OpenEx ("Basic_m.vss", (short) Visio.VisOpenSaveArgs.visOpenDocked); Visio.Shape shape1 = Currentpage.drop (currentstencil.masters["triangle"], 1.50, 1.50); Visio.Shape shape2 = Currentpage.drop (currentstencil.masters["Square"], 2.50, 3.50); Visio.Shape connector = currentpage.drop (currentstencil.masters["Dynamic connection Line"], 4.50, 4.50); ConnectShapes (Shape1, shape2, connector); Cell Arrowcell = CONNECTOR.GET_CELLSSRC (short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowLine, ( short) Visio.VisCellIndices.visLineEndArrow); Arrowcell.formulau = "5"; Connector.get_cells ("EndArrow"). Formula = "= 5"; } }}
Working with Visio paint in C #