Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
How to add a text box with scroll bar inside a word document?

الإجابة How to add a text box with scroll bar inside a word document?

  • Monday, September 13, 2010 4:41 PM
     
     

    Hi all,

    I would like to add a text box inside a word document. It should contain a scroll bar. IS there any way to do that. Please advise.

    • Edited by skh.hari Monday, September 13, 2010 4:43 PM making clear
    •  

All Replies

  • Tuesday, September 14, 2010 2:19 AM
    Moderator
     
     Answered Has Code

    Hi skh.hari,

    Since I don't know which one will you prefer, so I've used two methods.
    1. Add a UserControl to the project, on the UserControl you can just drag the textbox you need to the panel and
    set the ScrollBar property to Both, Horizontal, Vertical etc according to your own needs.
    Then you can add the usercontrol to the ActionPane of the document.
    I've made a Word Document Project. Here is the code snippet.

     private UserControl1 myControl1;
        private void ThisDocument_Startup(object sender, System.EventArgs e)
        {
          myControl1 = new UserControl1();
          this.ActionsPane.Controls.Add(myControl1);      
        }
    

    And the effect of it is like that:



    2. If you want the textBox embedded in the document. Then the code snippet is:

     private UserControl1 myTreeControl1;
        private void ThisDocument_Startup(object sender, System.EventArgs e)
        {
          myTreeControl1 = new UserControl1();
               Word.Application myApp = this.Application;
          
          this.Paragraphs[1].Range.InsertParagraphBefore();
          Microsoft.Office.Tools.Word.Controls.TextBox
             textBox1 = this.Controls.AddTextBox(
             this.Paragraphs[1].Range, 75, 15, "textBox1");
          Microsoft.Office.Tools.Word.Controls.RichTextBox
            richTextBox1 = this.Controls.AddRichTextBox(this.Paragraphs[2].Range,75,35,"richTextBox1");
          myApp.ActiveDocument.ActiveWindow.View.Zoom.Percentage = 100;
          
        }

    And the effect is like that:


    Furthermore, here is a link about AddTextBox method, hope it will be helpful.
    http://msdn.microsoft.com/en-us/library/a45d7wyb(VS.90).aspx

    Any further questions or if I misunderstood you, please feel free to contact. Thank you!

    Best Regards,
    Amy Li
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked As Answer by skh.hari Tuesday, September 14, 2010 12:57 PM
    •  
  • Tuesday, September 14, 2010 4:53 AM
    Moderator
     
     

    Hi skh.hari

    Mmm, Amy's suggestion assumes you're using VSTO...

    Are you working with VSTO, or something else? Which version of Word is involved, here? Which programming environment are you working in?


    Cindy Meister, VSTO/Word MVP
  • Tuesday, September 14, 2010 12:58 PM
     
     
    Thanks very much... To all of you... You people are right. Thanks  once again.