えムナウのプログラミングのページ

えムナウ の とどけもの

 Logo えムナウBlog@AILight
えムナウBlog@Wankuma

目次

利用状況

イメージ ギャラリー

カテゴリ

Links
 

inetaj

MSMVPロゴ
MSMVP Visual C# 2005/01-2007/12
SpreadControlのテストフォームです。

プログラムです。

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 System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private SpreadControl.SpreadControl spreadControl1;
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows フォーム デザイナ サポートに必要です。
			//
			InitializeComponent();

			//
			// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
			//
			spreadControl1[1,0].Text = "10" ;
			spreadControl1[1,0].BackColor = Color.Blue ;
			spreadControl1[1,0].ForeColor = Color.Yellow ;
			spreadControl1[1,1].Font = new Font("MS UI Gothic", 20) ;
			spreadControl1[1,1].Text = "a" ;
			spreadControl1[1,1].BackColor = Color.Red ;
			spreadControl1[1,1].ForeColor = Color.White ;
		}

		/// <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.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.spreadControl1 = new SpreadControl.SpreadControl();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.spreadControl1)).BeginInit();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(72, 40);
			this.button1.Name = "button1";
			this.button1.TabIndex = 0;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(512, 104);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "button2";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(504, 152);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "textBox1";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(504, 216);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.TabIndex = 7;
			// 
			// spreadControl1
			// 
			this.spreadControl1.AutoScroll = true;
			this.spreadControl1.AutoScrollMinSize = new System.Drawing.Size(376, 101);
			this.spreadControl1.BlockRange.Add(new SpreadControl.CellRange(1, 1, 3, 2));
			this.spreadControl1.BlockRange.Add(new SpreadControl.CellRange(3, 2, 4, 3));
			this.spreadControl1.BlockRange.Add(new SpreadControl.CellRange(0, 2, 1, 3));
			this.spreadControl1.BlockRange.Add(new SpreadControl.CellRange(2, 3, 4, 4));
			this.spreadControl1.Columns = 5;
			this.spreadControl1.Data = new SpreadControl.Cell[] {
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.Color.Brown),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.Color.Lime),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control),
																	new SpreadControl.Cell("", new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128))), System.Drawing.SystemColors.ControlText, System.Drawing.SystemColors.Control)};
			this.spreadControl1.Location = new System.Drawing.Point(72, 80);
			this.spreadControl1.Name = "spreadControl1";
			this.spreadControl1.PreferredColumnWidth = 75;
			this.spreadControl1.PreferredRowHeight = 20;
			this.spreadControl1.Rows = 5;
			this.spreadControl1.Size = new System.Drawing.Size(400, 200);
			this.spreadControl1.TabIndex = 8;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
			this.ClientSize = new System.Drawing.Size(656, 302);
			this.Controls.Add(this.spreadControl1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.spreadControl1)).EndInit();
			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(
						spreadControl1[i,j].Text);
				}
			}
			System.Diagnostics.Debug.WriteLine(
				spreadControl1.CurrentCell.ColumnNumber.ToString() + "," +
				spreadControl1.CurrentCell.RowNumber.ToString());
		}
	}
}