2014-02-12 4 views
0

Visio 파일에 사각형을 추가하고 글꼴 및 텍스트 색을 설정하려면 어떻게하면됩니까?Visio에서 모양, 글꼴 및 forecolor를 설정하는 방법

visio.Application app = new visio.Application(); 
visio.Document doc; 
doc = app.Documents.Open(processPath); 

visio.Page page = doc.Pages[1]; 
CreateVisio vis = new CreateVisio(); 
visio.Shape edit = page.DrawRectangle(3.2d, 6.9d, 4.9d, 7.9d); 

답변

2

새 VISIO 문서 너비를 가져 오는 방법을

Microsoft.Office.Interop.Visio.Application application = 
     new Microsoft.Office.Interop.Visio.Application(); 
application.Visible = false; 
Microsoft.Office.Interop.Visio.Document doc = application.Documents.Add(templatePath); 
Microsoft.Office.Interop.Visio.Page page = application.Documents[1].Pages[1]; 
과의 높이를 만드는 방법 당신이 일하고있는 시트

double xPosition = page.PageSheet.get_CellsU("PageWidth").ResultIU; 
double yPosition = page.PageSheet.get_CellsU("PageHeight").ResultIU; 

상자의 위치를 ​​알기 위해 용지 너비와 높이에 대한 정보를 사용하고 있습니다. 우리는 시트 폭을 뿌리 수로 나눔으로써 시트 중간에 루트 박스를 놓습니다. 또한 레벨 번호가 증가하는 상자가 차트에서 더 낮은 위치에 오도록 레벨 번호를 yPosition에서 뺍니다. Shape를 작성하고 차트에 배치하는 방법

//creating the type of shape in the organizational chart it could be: "Position", 
//"Executive", "Manager", "Assistant" and others according 
//to what you have in your stencil. 
Microsoft.Office.Interop.Visio.Master position = doc.Masters.get_ItemU("Position"); 
//placing the shape in the xPosition and yPosition coordinates 
Microsoft.Office.Interop.Visio.Shape shape = page.Drop(position, xPosition, yPosition); 

은 모양 속성 모양을 연결

//set the text 
shape.Text = box.Name; 

//set hyperlink 
if (!String.IsNullOrEmpty(box.HyperLink.Trim())) 
{ 
    Hyperlink link = shape.Hyperlinks.Add(); 
    link.Address = box.HyperLink; 
} 

//set the shape width 
shape.get_CellsSRC(
       (short)Microsoft.Office.Interop.Visio.VisSectionIndices. 
       visSectionObject, 
       (short)Microsoft.Office.Interop.Visio.VisRowIndices. 
       visRowXFormIn, 
       (short)Microsoft.Office.Interop.Visio.VisCellIndices. 
       visXFormWidth).ResultIU = box.Width; 

//set the shape height 
shape.get_CellsSRC(
       (short)Microsoft.Office.Interop.Visio.VisSectionIndices. 
       visSectionObject, 
       (short)Microsoft.Office.Interop.Visio.VisRowIndices. 
       visRowXFormIn, 
       (short)Microsoft.Office.Interop.Visio.VisCellIndices. 
       visXFormHeight).ResultIU = box.Height; 

//set the shape fore color 
shape.Characters.set_CharProps(
       (short)Microsoft.Office.Interop.Visio. 
        VisCellIndices.visCharacterColor, 
       (short)Utilities.GetVisioColor(box.ForeColor)); 

//set the shape back color 
shape.get_CellsSRC((short)VisSectionIndices.visSectionObject, 
     (short)VisRowIndices.visRowFill, 
    (short)VisCellIndices.visFillForegnd).FormulaU = 
    "RGB(" + box.BackColor.R.ToString() + "," + box.BackColor.G.ToString() + "," 
    + box.BackColor.B.ToString() + ")"; 

을 설정하는 방법 사용하여 수행됩니다 (버려) connectWithDynamicGlueAndConnector() 메소드 이 메소드는, 부모의 형상과 childShape의 2 개의 파라미터를 받아 들여, 그 사이에 커넥터를 작성합니다. 이 방법은 VISIO SDK에있는 정확한 방법입니다.

0

안녕하세요이 링크에서 그 답을 찾을

http://www.codeproject.com/Articles/109558/Creating-VISIO-Organigrams-using-C

+1

답변이 만족 스럽지만 문제를 해결할 수도 있지만 이와 같은 "링크 전용"답변을 게시하지 않는 것이 좋습니다. 링크가 앞으로 유효하지 않을 수있어 귀하의 답변이 쓸모 없게됩니다. 대신 원래 질문에 적용하고 작동에 대해 자세히 설명하는 링크에서 관련 코드를 복제하는 것이 좋습니다. –

관련 문제