Reputation: 13
I have mdi parent with split container control. I divided into two Panels.
Panel 1 contains child Form and Panel 2 contains some buttons like SAVE ,DELETE and UPDATE.
Panel 1 can be loaded with some Child forms. I Want to Call Methods of active Child form in Panel 1 when SAVE button is clicked.
Upvotes: 1
Views: 647
Reputation: 1071
you can use ActiveMdiChild
property to get active child of form.
Upvotes: 1
Reputation: 34421
You have to pass an instance of a form to use in a different class. See my two form project below :
Form 1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Form2 form2;
public Form1()
{
InitializeComponent();
form2 = new Form2(this);
}
private void button1_Click(object sender, EventArgs e)
{
form2.Show();
string results = form2.GetData();
}
}
}
Form 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
Form1 form1;
public Form2(Form1 nform1)
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(Form2_FormClosing);
form1 = nform1;
form1.Hide();
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
//stops form from closing
e.Cancel = true;
this.Hide();
}
public string GetData()
{
return "The quick brown fox jumped over the lazy dog";
}
}
}
Upvotes: 1