none
How can i reposition the text of visio dynamic connector in c# RRS feed

  • Question

  • Hi

    I am working on a web application which creates the Visio diagram depending upon the data in the database.

    Depending upon the data, different rectangular boxes are created and connected with the help of dynamic connector.

    I have added some information on the text property of the dynamic connector,But by default it get sets in the middle of the connector.

    I want to reposition this text dynamically in the beginning of the connector shape not in the middle.

    Can somebody please help me in doing this as i am fully stuck with this problem?

    I am posting my code which i am using to connect to the shapes.

            private void connectWithDynamicGlueAndConnector(Shape shapeFrom, Shape shapeTo, Page currentPage, Box box)
            {
                Microsoft.Office.Interop.Visio.Cell beginXCell;
                Microsoft.Office.Interop.Visio.Cell endXCell;
                Microsoft.Office.Interop.Visio.Shape connector;
               
                try
                {

                    // Add a Dynamic connector to the page.  //.FlowchartStencil
                    connector = dropMasterOnPage(
                        (Page)shapeFrom.ContainingPage,
                        "Dynamic Connector",
                        Utilities.FlowchartStencil, 1.0, 1.0);

                    //Added on 10/03/2011 for tooltip
                    connector.get_CellsSRC((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject,
                           (short)Microsoft.Office.Interop.Visio.VisRowIndices.visRowMisc,
                           (short)Microsoft.Office.Interop.Visio.VisCellIndices.visComment).FormulaU = "\"" + box.InterfaceInfo + "\"";

                    connector.get_CellsU("LineWeight").FormulaU = "2pt";
                    connector.get_CellsU("LineColor").Formula = arrowColor;//"RGB(255, 0, 0)";
                   
                    // Connect the begin point.
                    beginXCell = connector.get_CellsSRC(
                        (short)VisSectionIndices.visSectionObject,
                        (short)VisRowIndices.visRowXForm1D,
                        (short)VisCellIndices.vis1DBeginX);

                    beginXCell.GlueTo(shapeFrom.get_CellsSRC(
                        (short)VisSectionIndices.visSectionObject,
                        (short)VisRowIndices.visRowXFormOut,
                        (short)VisCellIndices.visXFormPinX));

                    // Connect the end point.
                    endXCell = connector.get_CellsSRC(
                        (short)VisSectionIndices.visSectionObject,
                        (short)VisRowIndices.visRowXForm1D,
                        (short)VisCellIndices.vis1DEndX);//

                    // Connect the end point.
                    endXCell.GlueTo(shapeTo.get_CellsSRC(
                        (short)VisSectionIndices.visSectionObject,
                        (short)VisRowIndices.visRowXFormOut,
                        (short)VisCellIndices.visXFormPinX));//

                    Cell arrowCellBegin = connector.get_CellsSRC((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, (short)Microsoft.Office.Interop.Visio.VisRowIndices.visRowLine, (short)Microsoft.Office.Interop.Visio.VisCellIndices.visLineBeginArrow);
                    if (box.blBoxType)
                        arrowCellBegin.FormulaU = "5";

                    Cell arrowCell = connector.get_CellsSRC((short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionObject, (short)Microsoft.Office.Interop.Visio.VisRowIndices.visRowLine, (short)Microsoft.Office.Interop.Visio.VisCellIndices.visLineEndArrow);
                    if (!box.blBoxType)
                        arrowCell.FormulaU = "5";

                    connector.Text = box.InterfaceDetails;

                }
                catch (Exception ex)
                {
                    objErrorLog.ErrorLog(ex.Message);
                }
                finally
                {
                    beginXCell = null;
                    endXCell = null;
                    connector = null;
                }
            }

    Any help would be appreciable.

    Thanks
    Dinesh
    Friday, August 5, 2011 6:59 AM

Answers

  • Hi Dinesh,

    After reading your post, I know want to change the position of the text in the shape, if I have misunderstood you, please let me know. But I found it difficult to reproduce your problem. How did you connect the shapes with data in the database? Which database did you use? From the function connectWithDynamicGlueAndConnector, I don't know what are the parameters stands for?

    So, it will be appreciate if you can tell me the reproducible steps of your problem. And could you send me a copy of your well running project, you can send me via this email: v-bpeng@microsoft.com I will do further research with your detailed information.

    PS: I recorded the macro in Visio by moving the text in the one shape and then got the following VBA code:

    Application.ActiveWindow.Page.Shapes.ItemFromID(6).CellsSRC(visSectionControls, 0, visCtlX).FormulaU = "1.999999874 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(6).CellsSRC(visSectionControls, 0, visCtlY).FormulaU = "Height/2+0 mm"

    I think you can modify a bit and use the code snippet in C# to change the position of the text in the shape.

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regard,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by 12dinesh12 Wednesday, August 10, 2011 9:05 AM
    Wednesday, August 10, 2011 7:20 AM

All replies

  • Hi Dinesh,

    After reading your post, I know want to change the position of the text in the shape, if I have misunderstood you, please let me know. But I found it difficult to reproduce your problem. How did you connect the shapes with data in the database? Which database did you use? From the function connectWithDynamicGlueAndConnector, I don't know what are the parameters stands for?

    So, it will be appreciate if you can tell me the reproducible steps of your problem. And could you send me a copy of your well running project, you can send me via this email: v-bpeng@microsoft.com I will do further research with your detailed information.

    PS: I recorded the macro in Visio by moving the text in the one shape and then got the following VBA code:

    Application.ActiveWindow.Page.Shapes.ItemFromID(6).CellsSRC(visSectionControls, 0, visCtlX).FormulaU = "1.999999874 mm"
    Application.ActiveWindow.Page.Shapes.ItemFromID(6).CellsSRC(visSectionControls, 0, visCtlY).FormulaU = "Height/2+0 mm"

    I think you can modify a bit and use the code snippet in C# to change the position of the text in the shape.

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regard,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by 12dinesh12 Wednesday, August 10, 2011 9:05 AM
    Wednesday, August 10, 2011 7:20 AM
  • HI Bruce

     

    Really Thanks for the reply.

    The same thing whatever you posted did not work but it gave me the direction to rectify my problem.

    The folllowing line of code works for me.

    connector.get_CellsU("TxtPinX").FormulaU = "Width * 0.5";

     

    Thanks Once again.


    Dinesh
    Wednesday, August 10, 2011 9:05 AM
  • Actually, your code will break the special behaviour of the text block of a Dynamic connector shape. You should have used: 

    connector.get_CellsU("Controls.TextPosition.X").FormulaU = "Width * 0.5";

    because the TxtPinX and TxtPinY cells contain formulas that reference Controls.TextPosition X and Y cells.

    The user normally moves the yellow control handle to move the text on aDynamic connector, and the text follows.... 


    David J Parker MVP (Visio) http://blog.bvisual.net

    Thursday, July 21, 2016 12:49 PM