I'll just post the code of both forms.
The error is at the bottom of the post.
First form (With textbox).
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsApplication3
- {
- public partial class Form1 : Form
- {
- public static string OpenTxt;
- public static string strFN;
- public Form2 form = new Form2();
- public Form1()
- {
- InitializeComponent();
- }
- private void saveToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Save();
- }
- private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
- {
- form.Show();
- }
- private void Save()
- {
- strFN = textBox2.Text + Form2.strExt;
- FileStream file = new FileStream(strFN, FileMode.Create, FileAccess.ReadWrite);
- StreamWriter sw = new StreamWriter(file);
- sw.Write(textBox1.Text);
- sw.Flush();
- sw.Close();
- }
- private void Open()
- {
- Open Open = new Open();
- Open.Show();
- }
- private void textBox1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.S && e.Modifiers == Keys.Control)
- Save();
- }
- private void openToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Open();
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsApplication3
- {
- public partial class Open : Form
- {
- public string strFO;
- public Open()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- strFO = textBox1.Text;
- FileStream reading = new FileStream(strFO, FileMode.Open);
- StreamReader sr = new StreamReader(reading);
- strFO = sr.ReadToEnd();
- sr.Close();
- Form1.OpenTxt = strFO;
- this.Close();
- }
- private void Open_FormClosing(object sender, FormClosingEventArgs e)
- {
- Form1.textBox1.Text = Form1.OpenTxt;
- }
- }
- }
BUT it gives me this error: Error 1 An object reference is required for the nonstatic field, method, or property 'WindowsApplication3.Form1.textBox1' C:\Users\robert\Documents\Visual Studio 2005\Projects\WindowsApplication3\WindowsApplicati on3\Open.cs 33 13 WindowsApplication3
Anybody know what I can do?
(textBox1 is set to public).