using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Sample
{
/// <summary>
/// Form2 の概要の説明です。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private Sample.UserControl1 userControl12;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public Form2()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.userControl12 = new Sample.UserControl1();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 208);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "100";
//
// userControl12
//
this.userControl12.Location = new System.Drawing.Point(80, 32);
this.userControl12.Name = "userControl12";
this.userControl12.TabIndex = 2;
this.userControl12.CalcEvet += new Sample.UserControl1.CalcEvetEventHandler(this.userControl12_CalcEvet);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.userControl12);
this.Controls.Add(this.textBox1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
private void userControl12_CalcEvet(object sender, System.EventArgs e)
{
MessageBox.Show("テストのメッセージ");
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Sample
{
/// <summary>
/// UserControl1 の概要の説明です。
/// </summary>
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Button btnA;
private System.Windows.Forms.Button btnB;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public delegate void CalcEvetEventHandler(object sender, EventArgs e);
public event CalcEvetEventHandler CalcEvet;
public UserControl1()
{
// この呼び出しは、Windows.Forms フォーム デザイナで必要です。
InitializeComponent();
// TODO: InitializeComponent 呼び出しの後に初期化処理を追加します。
this.btnA.Click += new EventHandler(CalcEvent);
this.btnB.Click += new EventHandler(CalcEvent);
// this.CalcEvet += new CalcEvetEventHandler(CalcEvent);
this.CalcEvet += new CalcEvetEventHandler(UserControl1_CalcEvet);
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region コンポーネント デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.btnA = new System.Windows.Forms.Button();
this.btnB = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnA
//
this.btnA.Location = new System.Drawing.Point(32, 32);
this.btnA.Name = "btnA";
this.btnA.TabIndex = 0;
this.btnA.Text = "btnA";
//
// btnB
//
this.btnB.Location = new System.Drawing.Point(32, 72);
this.btnB.Name = "btnB";
this.btnB.TabIndex = 1;
this.btnB.Text = "btnB";
//
// UserControl1
//
this.Controls.Add(this.btnB);
this.Controls.Add(this.btnA);
this.Name = "UserControl1";
this.ResumeLayout(false);
}
#endregion
public void CalcEvent(object sender, EventArgs e)
{
MessageBox.Show("ユーザコントロールの処理");
}
private void UserControl1_CalcEvet(object sender, EventArgs e)
{
MessageBox.Show("動かしたいのはこっちの動作");
}
}
}
|