用c#操作visio畫圖

來源:互聯網
上載者:User

標籤:

要想通過.net畫visio圖,要先將visio的com組件匯入,就是在引用中添加visio的com組件,匯入玩之後就可以寫代碼畫圖了。貼個簡單的範例程式碼,便於大家理解:

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.VisCellIndices.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.VisCellIndices.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)Visio.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.VisCellIndices.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["三角形"], 1.50, 1.50);            Visio.Shape shape2 = currentPage.Drop(currentStencil.Masters["正方形"], 2.50, 3.50);            Visio.Shape connector = currentPage.Drop(currentStencil.Masters["動態連接器"], 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";        }    }}

  

用c#操作visio畫圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.