Desi Bravo

Desi Bravo

  • NA
  • 25
  • 0

How to Save a ChildForm

Apr 24 2010 12:48 PM

Hello, I am trying to use the SaveDialog to save the contents of a textbox in a Childform from the parent menu file\save.
[code]
public partial class TextEditorForm : Form
{
int ChildOneCounterInteger;
StreamWriter editorStreamWriter;
public TextEditorForm()
{
InitializeComponent();
}
private void NewToolStripMenuItem_Click(object sender, EventArgs e)
{
ChildForm childOneForm = new ChildForm();
childOneForm.MdiParent =
this;
childOneForm.Show();
ChildOneCounterInteger++;
childOneForm.Text =
"Child One Document " + ChildOneCounterInteger.ToString();
childOneForm.Show();
}
private void openToolStripMenuItem1_Click(object sender, EventArgs e)
{
DialogResult responseDialogResult;
ofd.Filter =
"Text Files | *.txt | All Files | *.* | RichText Files | *.rtf";
ofd.InitialDirectory =
Directory.GetCurrentDirectory();
responseDialogResult = ofd.ShowDialog();
if (responseDialogResult != DialogResult.Cancel)
{
StreamReader sr;
sr =
new StreamReader(ofd.FileName);
sr.Close();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void tileToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(
MdiLayout.TileHorizontal);
}
private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(
MdiLayout.TileVertical);
}
private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
{
LayoutMdi(
MdiLayout.Cascade);
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{

if (ChildForm.txtEditor.Text != null)//Error 1 IT274_Desi_MDI.ChildForm.txtEditor' is inaccessible due to its protection level
//Error 2 An object reference is required for the non-static field, method, or property 'IT274_Desi_MDI.ChildForm.txtEditor'
{
editorStreamWriter.WriteLine(
this.txtEditor.Text);//
this.txtEditor.Clear();
txtEditor.Focus();
}
else
{
Mesagebox.Show(
"You must open the file before saving a record.",
MessageBoxButtons.OK, MessageBoxIcon.Information);
openToolStripMenuItem1(sender, e);
}
}

}
[/code]
Can  you help thanks.