Richtextbox not loading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shinobi
    New Member
    • Nov 2008
    • 7

    Richtextbox not loading

    c#.net
    I have 2 forms. richtextbox1 is placed in form1.
    listbox1 is used in form2. selectedindex of listbox1 is passing path to form1.
    by using this path i am trying to load richtextbox1 using this code

    richtextbox1.lo adFile(filepath );

    But i can't load richtextbox without closing form2.

    I tried this meathod.

    form2 ob2=new form2();
    ob2.showdialog( );
    string filepath=ob2.la bel1.text;
    richtextbox1.lo adfile(filepath );

    In selectedIndex of listbox1 in form2

    //geting filepath
    label.text=file path;
    this.close();


    I want to load richtextbox without closing form2.

    Is there is any meathod to load Richtextbox in this way?

    Help me....
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    There's a number of ways to do this. One simple method could be to pass a reference of your RichTextBox to form 2.

    Maybe you could add a property to form 2 called "TargetText Box" or something, like so:

    Code:
            private RichTextBox _textbox;
    
            public RichTextBox TargetTextBox
            {
                get { return _textbox; }
                set { _textbox = value;  }
            }
    Then in form 1 you can set this reference before displaying form 2, like so:

    Code:
    form2 ob2=new form2();
    obj2.TargetTextBox = richTextBox1;
    ob2.showdialog();
    Then in selected index event in form2 you can have full access to the textbox:

    Code:
    // Get file path somehow
    TargetTextBox.LoadFile(filepath);

    Comment

    • MrMancunian
      Recognized Expert Contributor
      • Jul 2008
      • 569

      #3
      Hi,

      The problem is in ob2.showdialog( ); When you use this, the code will not continue to execute unless the dialog is closed. Try to use ob2.show();

      Steven

      Comment

      • nukefusion
        Recognized Expert New Member
        • Mar 2008
        • 221

        #4
        Hi,

        The problem is in ob2.showdialog( ); When you use this, the code will not continue to execute unless the dialog is closed. Try to use ob2.show();

        Steven
        That is true, but using the code sample Shinobi provided, you would still need a way to reference the RichTextBox in form 1 so that you could load it when the selected index event of the listbox on form 2 fires. As is, if the ShowDialog() command was changed to Show(), form2 would open, but the richtextbox would never be loaded.

        Comment

        Working...