This is a migrated thread and some comments may be shown as answers.

Fold/UnFold Programmatically

1 Answer 193 Views
SyntaxEditor
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Veteran
Jason asked on 14 Aug 2020, 02:02 PM

I'd like to have my regions folded when new .CS is loaded.. is there a way to programatically fold / unfold the display text? 

Closest thing I could find was this:  radSyntaxEditor1.SyntaxEditorElement.FoldingManager.UnfoldAllRegionsContaningIndex(1);

Thanks!  Jason

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Aug 2020, 06:36 AM
Hello, Jason,

The SyntaxEditorElement.FoldingManager offers the FoldingRegions collection. You can iterate its items and set the FoldingRegion.IsFolded to true/false according to the fold/unfold action that you want to perform: 
        public RadForm1()
        {
            InitializeComponent();

            CSharpTagger currentLanguageTagger = new Telerik.WinForms.Controls.SyntaxEditor.Taggers.CSharpTagger(this.radSyntaxEditor1.SyntaxEditorElement);
            this.radSyntaxEditor1.TaggersRegistry.RegisterTagger(currentLanguageTagger);

            CSharpFoldingTagger foldingTagger = new Telerik.WinForms.Controls.SyntaxEditor.Taggers.CSharpFoldingTagger(this.radSyntaxEditor1.SyntaxEditorElement);
            foldingTagger.FoldingRegionDefinitions.Add(new FoldingRegionDefinition("#region", "#endregion"));
            radSyntaxEditor1.TaggersRegistry.RegisterTagger(foldingTagger);

           
            using (StreamReader reader = new StreamReader(@"..\..\document.cs"))
            {
                this.radSyntaxEditor1.Document = new TextDocument(reader);
            }

        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            foreach (FoldingRegion region in this.radSyntaxEditor1.SyntaxEditorElement.FoldingManager.FoldingRegions)
            {
                region.IsFolded = true;
            }
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Tags
SyntaxEditor
Asked by
Jason
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or