1

I have a MDIChild form ,Normal Form called form1 inherited from MDIChild form and MDIParent form ,there is a tool bar top of the MDIParent form in that tool bar there is a New button, when I click on new button it loads the Form1 below the tool bar inside the parent form

There is a TextBox inside the form1 and when I click the save button the value of the TextBox should be shown in a MessageBox by calling its function,

But the thing is I cant access the TextBox Text property??

And my MDIParent form code is

 public partial class MDIParent1 : Form
{
   // private int childFormNumber = 0;
    MdiClient mdi = null;
    string fname;



    public MDIParent1()
    {
        InitializeComponent();
        foreach (Control c in this.Controls)
        {
            if (c is MdiClient)
            {
                mdi = (MdiClient)c;
                break;
            }
        }
    }

  private void load_form(object form)
    {
        foreach (Form f in mdi.MdiChildren)
        {
            f.Close();

        }
        if (form == null)
            return;
        ((Form)form).MdiParent = this;
        ((Form)form).Show();
        ((Form)form).AutoScroll = true;



        fname = ((Form)form).Name;



    }

 private void newToolStripButton_Click(object sender, EventArgs e)
    {
        load_form(new Form1());
    }

 private void saveToolStripButton_Click(object sender, EventArgs e)
    {
        if (fname == "Form1")
        {
            Form1 f1 = new Form1();
            f1.show_message();

        }


    }

In my form1 code is

public void show_message()
    {
        MessageBox.Show(textBox1.Text);
    }

My MDIChild form code is

 public mdichild()
    {
        InitializeComponent();
        this.Load += new EventHandler(this.mdichild_Load);

    }

    private void mdichild_Load(object sender, EventArgs e)
    {
        this.ControlBox = false;
        this.WindowState = FormWindowState.Maximized;
        this.BringToFront();
        int h = Screen.PrimaryScreen.Bounds.Height;
        int w = Screen.PrimaryScreen.Bounds.Width;
        this.MinimumSize = new Size(w, h);
    }

Can Anyone help me?

analyticalpicasso
  • 1,993
  • 8
  • 26
  • 45
Roshan
  • 3,236
  • 10
  • 41
  • 63

1 Answers1

0

I understand what you are doing some accessing MDIChild form data. try this :--

 private void ShowNewForm(object sender, EventArgs e)
    {
        Form childForm = new Form();
        childForm.MdiParent = this;
       // childForm.ContextMenuStrip = contextMenuStrip1;
        //this.contextMenuStrip1.ResumeLayout(false);
        RichTextBox text = new RichTextBox();
        text.Dock = DockStyle.Fill;
        childForm.Controls.Add(text);
        childForm.Text = "Page  " + this.MdiChildren.Count();
        childForm.Show();
    }

    private void OpenFile(object sender, EventArgs e)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
        if (openFileDialog.ShowDialog(this) == DialogResult.OK)
        {
            string FileName = openFileDialog.FileName;
        }
    }
    private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
        if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
        {
            string FileName = saveFileDialog.FileName;
        }
    }
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
DOT.NET
  • 101
  • 14