2016-04-16 15 views
0

私はsplit container controlを持つmdi parentを持っています。私は2つのパネルに分割しました。mdi親フォームからアクティブなmdichildフォームのメソッドを呼び出すには

パネル1には子フォームがあり、パネル2にはSAVE、DELETE、UPDATEなどのボタンがいくつか含まれています。

パネル1には、いくつかの子フォームをロードできます。 SAVEボタンをクリックするとパネル1のアクティブ子フォームのメソッドを呼び出したい。

答えて

0

:以下の私の2つのフォームプロジェクトを参照してください。

+0

両方のおかげで、私はそれからいくつかのアイデアを得た。 – selvin

+0

あなたはウェルカムです。 –

1

異なるクラスで使用するには、フォームのインスタンスを渡す必要があります。

フォームフォームのアクティブな子を取得するためにActiveMdiChildプロパティを使用することができます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(); 
     } 
    } 
} 

フォーム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"; 
     } 

    } 
} 
関連する問題