当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Visio.CenterDrawing方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Visio.CenterDrawing方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Visio.CenterDrawing方法的具体用法?C# Microsoft.Office.Interop.Visio.CenterDrawing怎么用?C# Microsoft.Office.Interop.Visio.CenterDrawing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Visio的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Visio.CenterDrawing方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisualizeUsers


//.........这里部分代码省略.........

            try
            {
                // Turn on all Visio diagram services
                targetDocument = targetPage.Document;
                visioApplication = targetPage.Application;
                stencilUML = visioApplication.Documents.
                            OpenEx(@"C:\MyTestProjects\MCD\diploma\pmtool\pmt\pmt\UML_Class.vssx",
                                    (short)Visio.VisOpenSaveArgs.visOpenHidden);
                // Enable All Diagram Services to enable adding huge-named members to the container
                prevDiagramServices = targetDocument.DiagramServicesEnabled;
                targetDocument.DiagramServicesEnabled = currentDiagramServices;

                // DO NOT REMOVE NEXT LINE!
                //-- WTF?! Добавление этой строчки убирает из Container'а дефолтные члены.
                //-- Причем только для первого раза. Если создавать еще сущности, то уже будет опять с дефолтными.
                //
                //-- Вместо этой строки сейчас просто удаляются дефолтные члены контейнеров.
                //-- Благо, их генерится всего два, и удаление не занимает много времени.
                //targetPage.Document.OpenStencilWindow();

                // Just drop elements from User Table:
                //foreach (User u in db.User)
                //{
                //    System.Diagnostics.Debug.WriteLine(lastElemInContainer);
                //    shapeUser = targetPage.Drop(stencilUML.Masters["Member"], 0, 0);
                //    shapeUser.Text = String.Format("name: {0}|password: {1}|policy: {2}", u.Name, u.Password, u.Policy_Id);
                //    //shapeUser.Text = String.Format("name: {0}", u.Name);
                //    targetPage.Application.ActiveWindow.Select(shapeUser, (short)Visio.VisSelectArgs.visSelect);
                //}

                // Drop a container
                shapeUserContainer = targetPage.DropContainer(stencilUML.Masters["Class"], null);
                // Same as prev.row:
                //shapeUserContainer = targetPage.Drop(stencilUML.Masters["Class"], 5, 5);
                shapeUserContainer.Text = "User Table";

                // Get/Set Container List Spacing Interval (gap between members in list)
                //shapeUserContainer.ContainerProperties.SetListSpacing(Visio.VisUnitCodes.visInches, 0.2);
                //System.Diagnostics.Debug.WriteLine(shapeUserContainer.ContainerProperties.GetListSpacing(Visio.VisUnitCodes.visInches));

                // Delete default members, that appear right after a container was dropped on a page
                foreach (int o in shapeUserContainer.ContainerProperties.GetMemberShapes((int)Visio.VisContainerFlags.visContainerFlagsDefault))
                {
                    targetPage.Shapes.get_ItemFromID(o).Delete();
                }

                // Drop elements to the container
                lastElemInContainer = shapeUserContainer.ContainerProperties.GetListMembers().Length+1;
                foreach (User u in db.User)
                {
                    System.Diagnostics.Debug.WriteLine(lastElemInContainer);
                    if (lastElemInContainer != 1)
                    {
                        shapeUser = targetPage.DropIntoList(stencilUML.Masters["Separator"],
                                                            shapeUserContainer,
                                                            lastElemInContainer);
                        lastElemInContainer += 1;
                    }
                    shapeUser = targetPage.DropIntoList(stencilUML.Masters["Member"],
                                                            shapeUserContainer,
                                                            lastElemInContainer);
                    lastElemInContainer += 1;
                    shapeUser.Text = String.Format("name: {0}|password: {1}|policy: {2}", u.Name, u.Password, u.Policy_Id);

                    // Same with Insert method:
                    //shapeUserContainer.ContainerProperties.InsertListMember(
                    //    shapeUser = targetPage.Drop(stencilUML.Masters.get_ItemU("Member"),0,0), lastElemInContainer);
                    //shapeUser.Text = String.Format("Name: {0}|Password: {1}|Policy: {2}", u.Name, u.Password, u.Policy_Id);
                    //lastElemInContainer += 1;
                }

                containerProperties = shapeUserContainer.ContainerProperties;
                // Report on contents of container
                containerMembers = containerProperties.GetMemberShapes((int)Visio.VisContainerFlags.visContainerFlagsDefault);
                foreach (int member in containerMembers)
                {
                    System.Diagnostics.Debug.WriteLine(targetPage.Shapes.get_ItemFromID(member).NameU +
                        " |===> "+ targetPage.Shapes.get_ItemFromID(member).Text);
                }

                targetPage.Application.ActiveWindow.DeselectAll();
                targetPage.CenterDrawing();
                stencilUML.Close();
                targetDocument.DiagramServicesEnabled = prevDiagramServices;
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                // Return the Diagram Services status to its previous state if it was set in
                // the try block.
                if (currentDiagramServices != -1 && targetDocument != null)
                {
                    targetDocument.DiagramServicesEnabled = currentDiagramServices;
                }
                throw;
            }

            return Program.ExitCode.Success;
        }
开发者ID:romos,项目名称:pmtool,代码行数:101,代码来源:Visualizer.cs

示例2: VisualizeURP


//.........这里部分代码省略.........
                        {
                            if (maxStrLenPerms == 0)
                                strPerms.Add(String.Format("Name: {0}, Policy_Id: {1}", p.Name, p.Policy_Id));
                            else
                                strPerms.Add(String.Format("\nName: {0}, Policy_Id: {1}", p.Name, p.Policy_Id));

                            if (strPerms.Last().Length > maxStrLenPerms)
                                maxStrLenPerms = strPerms.Last().Length;
                        }
                    }
                    shape = targetPage.Drop(stencilBasicU.Masters["Rectangle"],centerX, centerY += H + gap);
                    double charSize = shape.get_Cells("Char.Size").ResultIU;
                    shape.get_Cells("Height").ResultIU = charSize * strPerms.Count + 2 * border;
                    shape.get_Cells("Width").ResultIU = charSize * maxStrLenPerms;
                    shape.Text = String.Concat(strPerms);

                    shapePermissions.Add(shape);

                    strPerms.Clear();
                    maxStrLenPerms = 0;
                }

                //Left-Side Alignment of Permission Rectangles
                if (shapePermissions.Count != 0)
                {
                    foreach (var sh in shapePermissions)
                        selection.Select(sh, (short)Visio.VisSelectArgs.visSelect);
                    selection.Align(Visio.VisHorizontalAlignTypes.visHorzAlignLeft,
                                    Visio.VisVerticalAlignTypes.visVertAlignNone);
                    selection.DeselectAll();
                }

                // Drop Roles (Use Case Objects)
                shapeRoles = new List<Visio.Shape>();
                int i = 0;
                foreach (var rp in rpSet)
                {
                    shape = targetPage.DropConnected(stencilUMLUseCase.Masters["Use Case"],
                                                    shapePermissions.ElementAt(i),
                                                    Visio.VisAutoConnectDir.visAutoConnectDirLeft);
                    shape.Text = String.Format("name: {0}|policy: {1}|cardinality:{2}",
                                                rp.Key.Name, rp.Key.Policy_Id, rp.Key.Cardinality);
                    shapeRoles.Add(shape);
                    selection.Select(shape, (short)Visio.VisSelectArgs.visSelect);
                    i++;
                }

                // Drop a container
                shapeContainer = targetPage.DropContainer(stencilUMLUseCase.Masters["Subsystem"],
                                                            (shapeRoles.Count==0?null:selection));
                shapeContainer.Text = (shapeRoles.Count==0?"NO ROLE AUTHORIZED":"Authorized roles");
                selection.DeselectAll();

                // Move Container to the left to avoid overlapping with Permission Rectangles
                selection.Select(shapeContainer, (short)Visio.VisSelectArgs.visSelect);
                selection.Move(-1, 0);
                selection.DeselectAll();

                // Get height of the container and add a User to the left.
                // Can't use general method DropConnected, cause the container doesn't have such a property
                double containerH = shapeContainer.get_Cells("Height").ResultIU;
                double containerW = shapeContainer.get_Cells("Width").ResultIU;
                double containerXPos = shapeContainer.get_Cells("PinX").ResultIU;
                double containerYPos = shapeContainer.get_Cells("PinY").ResultIU;
                shape = targetPage.Drop(stencilUMLUseCase.Masters["Actor"], containerXPos - containerW / 2 - 1, containerYPos);
                shape.Text = String.Format("USER\nName: {0}\nPassword: {1}\nPolicy_Id: {2}",
                                            user_in.Name,
                                            user_in.Password,
                                            user_in.Policy_Id);
                shapeConnector = targetPage.Drop(stencilUMLUseCase.Masters["Association"], 0, 0);
                ConnectShapes(shape, shapeContainer, shapeConnector);

                // Report on contents of container
                containerProperties = shapeContainer.ContainerProperties;
                containerMembers = containerProperties.GetMemberShapes((int)Visio.VisContainerFlags.visContainerFlagsDefault);
                foreach (int member in containerMembers)
                {
                    System.Diagnostics.Debug.WriteLine(targetPage.Shapes.get_ItemFromID(member).NameU +
                        " |---> " + targetPage.Shapes.get_ItemFromID(member).Text);
                }

                // Finalize
                targetPage.Application.ActiveWindow.DeselectAll();
                targetPage.CenterDrawing();
                stencilUMLUseCase.Close();
                //targetPage.Name = String.Format("URP | Usr:{0};Pol:{1}",user_in.Name,user_in.Policy_Id);
                targetDocument.DiagramServicesEnabled = prevDiagramServices;
            }
            catch (Exception err)
            {
                System.Diagnostics.Debug.WriteLine(err.Message);
                // Return the Diagram Services status to its previous state if it was set in the try block.
                if (currentDiagramServices != -1 && targetDocument != null)
                    targetDocument.DiagramServicesEnabled = currentDiagramServices;
                throw;
                //return Program.ExitCode.Error;
            }

            return Program.ExitCode.Success;
        }
开发者ID:romos,项目名称:pmtool,代码行数:101,代码来源:Visualizer.cs

示例3: ResizeToFitContents

        public static void ResizeToFitContents(IVisio.Page page, Drawing.Size padding)
        {
            // first perform the native resizetofit
            page.ResizeToFitContents();

            if ((padding.Width > 0.0) || (padding.Height > 0.0))
            {
                // if there is any additional padding requested
                // we need to further handle the page

                // first determine the desired page size including the padding
                // and set the new size

                var old_size = PageHelper.GetSize(page);
                var new_size = old_size + padding.Multiply(2, 2);
                PageHelper.SetSize(page,new_size);

                // The page has the correct size, but
                // the contents will be offset from the correct location
                page.CenterDrawing();
            }
        }
开发者ID:shekharssorot2002,项目名称:VisioAutomation2.0,代码行数:22,代码来源:PageHelper.cs


注:本文中的Microsoft.Office.Interop.Visio.CenterDrawing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。