using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace smDragDropTestApp
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class smDragDropTest : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		public const int MAX_GRID_SIZE = 4;
		public const int IMAGE_WIDTH = 50;
		public const int IMAGE_HEIGHT = 50;
		public const int BORDER_OFFSET = 5;
		private smTile[,] grid;
		public smDragDropTest()
		{
			int xSpot;
			int ySpot;
			// 初始化网格
			grid = new smTile[MAX_GRID_SIZE, MAX_GRID_SIZE];

			// 初始化网格中的图片
			for (int row = 0; row < MAX_GRID_SIZE; row++) 
			{
				for (int col = 0; col < MAX_GRID_SIZE; col++) 
				{
					try 
					{
						// 生成贴图
						grid[row,col] = new smTile();

						// 设置位置
						xSpot = (col * IMAGE_WIDTH) + BORDER_OFFSET;
						ySpot = (row * IMAGE_HEIGHT) + BORDER_OFFSET;						
						grid[row,col].Location = new Point(xSpot, ySpot);

						// 把贴图放在窗体上
						this.Controls.Add(grid[row,col]);
					}
					catch 
					{
						System.Console.WriteLine("Exception caught for tile[{0}, {1}]", row, col);
					}
                    
				}
			}

			// 设置窗体信息
			this.Width = (BORDER_OFFSET * 2) + (MAX_GRID_SIZE * IMAGE_WIDTH) + 10;
			this.Height = (BORDER_OFFSET * 2) + (MAX_GRID_SIZE * IMAGE_HEIGHT) + 28;
			this.Text = "拖拉练习";
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
                                    
			// 事前设置3个点
			grid[0,0].PutItem();
			grid[1,1].PutItem();
			grid[2,2].PutItem();
		
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		public static void Main()  
		{
			try 
			{
				Application.Run(new smDragDropTest());
			}
			catch 
			{
				System.Console.WriteLine("Exception caught");
			}
		}	
	}
}
