| SpreadControl1 | テキストボックスを5つ配置してインデクサでアクセスできるようにした例です。 |
| SpreadControl2 | SpreadControl1 を5つ配置してインデクサでアクセスできるようにした例です 。 |
| SpreadTest | SpreadControl2 を配置して5x5のスプレッドシートです。 (1,1)に初期値を入れています。 button1 を押すとデバッガ出力でスプレッドシートの入力値が確認できます。 |
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace SpreadControl1
{
/// <summary>
/// UserControl1 の概要の説明です。
/// </summary>
public class SpreadControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox5;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public SpreadControl1()
{
// この呼び出しは、Windows.Forms フォーム デザイナで必要です。
InitializeComponent();
// TODO: InitComponent 呼び出しの後に初期化処理を追加してください。
}
/// <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.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox1.Location = new System.Drawing.Point(0, 0);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox2.Location = new System.Drawing.Point(100, 0);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 1;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox3.Location = new System.Drawing.Point(200, 0);
this.textBox3.Name = "textBox3";
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// textBox4
//
this.textBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox4.Location = new System.Drawing.Point(300, 0);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 3;
this.textBox4.Text = "";
//
// textBox5
//
this.textBox5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.textBox5.Location = new System.Drawing.Point(400, 0);
this.textBox5.Name = "textBox5";
this.textBox5.TabIndex = 4;
this.textBox5.Text = "";
//
// SpreadControl1
//
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "SpreadControl1";
this.Size = new System.Drawing.Size(500, 19);
this.ResumeLayout(false);
}
#endregion
public string this [int index]
{
get
{
switch( index )
{
case 1-1: return textBox1.Text ;
case 2-1: return textBox2.Text ;
case 3-1: return textBox3.Text ;
case 4-1: return textBox4.Text ;
case 5-1: return textBox5.Text ;
}
return "" ;
}
set
{
switch( index )
{
case 1-1: textBox1.Text = value ; break ;
case 2-1: textBox2.Text = value ; break ;
case 3-1: textBox3.Text = value ; break ;
case 4-1: textBox4.Text = value ; break ;
case 5-1: textBox5.Text = value ; break ;
}
}
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace SpreadControl2
{
/// <summary>
/// UserControl1 の概要の説明です。
/// </summary>
public class SpreadControl2 : System.Windows.Forms.UserControl
{
private SpreadControl1.SpreadControl1 spreadControl11;
private SpreadControl1.SpreadControl1 spreadControl12;
private SpreadControl1.SpreadControl1 spreadControl13;
private SpreadControl1.SpreadControl1 spreadControl14;
private SpreadControl1.SpreadControl1 spreadControl15;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public SpreadControl2()
{
// この呼び出しは、Windows.Forms フォーム デザイナで必要です。
InitializeComponent();
// TODO: InitComponent 呼び出しの後に初期化処理を追加してください。
}
/// <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.spreadControl11 = new SpreadControl1.SpreadControl1();
this.spreadControl12 = new SpreadControl1.SpreadControl1();
this.spreadControl13 = new SpreadControl1.SpreadControl1();
this.spreadControl14 = new SpreadControl1.SpreadControl1();
this.spreadControl15 = new SpreadControl1.SpreadControl1();
this.SuspendLayout();
//
// spreadControl11
//
this.spreadControl11.Location = new System.Drawing.Point(0, 0);
this.spreadControl11.Name = "spreadControl11";
this.spreadControl11.Size = new System.Drawing.Size(500, 19);
this.spreadControl11.TabIndex = 0;
//
// spreadControl12
//
this.spreadControl12.Location = new System.Drawing.Point(0, 19);
this.spreadControl12.Name = "spreadControl12";
this.spreadControl12.Size = new System.Drawing.Size(500, 19);
this.spreadControl12.TabIndex = 1;
//
// spreadControl13
//
this.spreadControl13.Location = new System.Drawing.Point(0, 38);
this.spreadControl13.Name = "spreadControl13";
this.spreadControl13.Size = new System.Drawing.Size(500, 19);
this.spreadControl13.TabIndex = 2;
//
// spreadControl14
//
this.spreadControl14.Location = new System.Drawing.Point(0, 57);
this.spreadControl14.Name = "spreadControl14";
this.spreadControl14.Size = new System.Drawing.Size(500, 19);
this.spreadControl14.TabIndex = 3;
//
// spreadControl15
//
this.spreadControl15.Location = new System.Drawing.Point(0, 76);
this.spreadControl15.Name = "spreadControl15";
this.spreadControl15.Size = new System.Drawing.Size(500, 19);
this.spreadControl15.TabIndex = 4;
//
// SpreadControl2
//
this.Controls.Add(this.spreadControl15);
this.Controls.Add(this.spreadControl14);
this.Controls.Add(this.spreadControl13);
this.Controls.Add(this.spreadControl12);
this.Controls.Add(this.spreadControl11);
this.Name = "SpreadControl2";
this.Size = new System.Drawing.Size(500, 95);
this.ResumeLayout(false);
}
#endregion
public SpreadControl1.SpreadControl1 this [int index]
{
get
{
switch( index )
{
case 1-1: return spreadControl11 ;
case 2-1: return spreadControl12 ;
case 3-1: return spreadControl13 ;
case 4-1: return spreadControl14 ;
case 5-1: return spreadControl15 ;
}
return null ;
}
set
{
switch( index )
{
case 1-1: spreadControl11 = value ; break ;
case 2-1: spreadControl12 = value ; break ;
case 3-1: spreadControl13 = value ; break ;
case 4-1: spreadControl14 = value ; break ;
case 5-1: spreadControl15 = value ; break ;
}
}
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace SpreadTest
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private SpreadControl2.SpreadControl2 spreadControl21;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
spreadControl21[1][1] = "a" ;
}
/// <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.spreadControl21 = new SpreadControl2.SpreadControl2();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// spreadControl21
//
this.spreadControl21.Location = new System.Drawing.Point(24, 16);
this.spreadControl21.Name = "spreadControl21";
this.spreadControl21.Size = new System.Drawing.Size(500, 95);
this.spreadControl21.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(448, 128);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(544, 158);
this.Controls.Add(this.button1);
this.Controls.Add(this.spreadControl21);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
for (int i=0 ; i<5 ;i++ )
{
for (int j=0 ; j<5 ; j++ )
{
System.Diagnostics.Debug.WriteLine(spreadControl21[i][j]);
}
}
}
}
}