Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does exist in C# a REFRESH function for a form ?!!

Status
Not open for further replies.

Alric2rei

Programmer
Jul 17, 2009
4
RO
I have 2 forms and on :

Form_1 I have : 1_button + 1_richTextBox
Form_2 I have : 1_button

When I click the button from my Form_2 open a FileDialog window to select a txt file and with StreamReader I read the content and send it to be placed in the richTextBox from my Form_1

It works but only if I open again the Form_1 with ShowDialog()

and I don't want to use ShowDialog() again I want something like a REFRESH of FORM_1

Here's My Code

====== FORM__1 =========

Code:
public partial class Form1 : Form
    {

        Form2 obj = new Form2(); // object for second FORM_2

        public Form1()
        {
            InitializeComponent();
      
        }

        public Form1(string mesaj)
        {
            InitializeComponent();
            textBox1.Text = mesaj;
            
     
        }

      private void button1_Click(object sender, EventArgs e)
        {
            obj.Show(); // calling the second FORM_2

        }

======== Form__2 ==============
Code:
public partial class Form2 : Form
    {
       
        public Form2()
        {
            InitializeComponent();
        }

      private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog deschide = new OpenFileDialog();

            deschide.Filter = "*.txt|";
            if (deschide.ShowDialog() == DialogResult.OK)
            {
 StreamReader citeste = new StreamReader(deschide.FileName);
 Form1 obiect = new Form1(citeste.ReadToEnd());
 obiect.Show(); // open again the form_1 to see the text in  
                   the richtextBox
 this.Close(); // close FORM_2
            }
        }
    }

Bottom line is
when run the application want to see FORM_1 click the button and open second FORM_2 open and read content from a txt file and send it to the richTextBox form FORM_1 without using the ShowDialog() function to Reopen the FORM_1 so I could see the text.

I want something like Refresh if Exist

Thanks
 
Does the file open have to happen on the Form2?? Why not move

Code:
OpenFileDialog deschide = new OpenFileDialog();

to Form1?

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top