Locked Can txt content display on TextBox?

  • Wednesday, August 15, 2012 12:45 AM
     
      Has Code

    Thank you for your help first.

    So far, I already can use openfiledialog component to control txt file.

    But now, I also want to that the file's content display to textbox

    Such as below, Path of file display textbox2, and I want to display txt's content into textbox1.

    How can I do?

    	private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
    				 
          
          OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
    
          openFileDialog1->InitialDirectory = "c:\\";
          openFileDialog1->Filter = "All files (*.*)|*.*|Txt Files (*.txt)|*.txt";
          openFileDialog1->FilterIndex = 2;
          openFileDialog1->RestoreDirectory = true;
    
          if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
          {
    		 textBox2->Text = openFileDialog1->FileName; 
    		
    		 
          }
    			 }

    In addition,

    I use project which is windows forms application.


    • Edited by Chris Sun Wednesday, August 15, 2012 1:01 AM
    •  

All Replies

  • Wednesday, August 15, 2012 2:49 AM
     
     

    But now, I also want to that the file's content display to textbox

    How to: Read Text from a File
    http://msdn.microsoft.com/en-us/library/db5x7c0d.aspx#Y0

    - Wayne
  • Wednesday, August 15, 2012 11:01 AM
     
     
    Thank you for your help first.
     
    So far, I already can use openfiledialog component to control txt file.
     
    But now, I also want to that the file's content display to textbox
     
    Such as below, Path of file display textbox2, and I want to display txt's content into textbox1.
    Then your question has nothing to do with textboxes. You know how to display text in a textbox. What you want to know is how to read text from a file.
     
    Wayne has given you a reference.
     

    David Wilkinson | Visual C++ MVP
  • Wednesday, August 15, 2012 12:18 PM
     
     Answered

    I want to display txt's content into textbox1.

    Note also that if you use a RichTextBox instead of a
    TextBox then you can simply use the LoadFile() member
    function.

    RichTextBox::LoadFile Method (String, RichTextBoxStreamType)
    http://msdn.microsoft.com/en-us/library/d76176b1.aspx

    - Wayne
    • Marked As Answer by Chris Sun Thursday, August 16, 2012 3:21 AM
    •