none
Poweproint C# VSTO - setting TextFrame Ruler Level margins RRS feed

  • Question

  • Hi all,

    I have an old ribbon addin written in VBA and I'm going through updating this to C#. I'm finding one or two things are catching me out and the current one is setting Ruler Levels.

    Say I create a textbox, populate it with 5 paragraphs and set those paragraphs to 5 indent levels respectively. I then want to set the LeftMargin and FirstMargin of each level. I can do this in VBA but for some reason in C# this seems to only write the last level values to the first level.

    How do I make this work, currently trying adding shape rather than textbox but result same to date:

    Shape Textbox = CurrentSlide.Shapes.AddShape(Type, Left, Top, Width, Height);
    
    Textbox.TextFrame.TextRange.Text =
                    "First level" + System.Environment.NewLine +
                    "Second level" + System.Environment.NewLine +
                    "Third level" + System.Environment.NewLine +
                    "Fourth level" + System.Environment.NewLine +
                    "Fifth level" + System.Environment.NewLine;
    
                Textbox.TextFrame.TextRange.Paragraphs(1).IndentLevel = 1;
    Textbox.TextFrame.TextRange.Paragraphs(2).IndentLevel = 2;
    Textbox.TextFrame.TextRange.Paragraphs(3).IndentLevel = 3;
    Textbox.TextFrame.TextRange.Paragraphs(4).IndentLevel = 4;
    Textbox.TextFrame.TextRange.Paragraphs(5).IndentLevel = 5;
    
    Textbox.TextFrame.Ruler.Levels[1].FirstMargin = 60f
    Textbox.TextFrame.Ruler.Levels[1].LeftMargin = 70f;
    Textbox.TextFrame.Ruler.Levels[2].FirstMargin = 80f
    Textbox.TextFrame.Ruler.Levels[2].LeftMargin = 90f;

    Feels like everything prior to the final pair of margins gets overwritten before submitted to the shape? Sometimes that will mean level2 gets written, other times with different code the level 2 values would write into level 1. When I'm trying to do margins for all 5 chaos ensues!

    As I say, I can make this work in VBA but not C# VSTO. Any ideas or pointers greatly appreciated.

    Thanks


    • Edited by DavidKerley Thursday, October 3, 2019 4:51 PM
    Thursday, October 3, 2019 4:49 PM