Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Puzzle - Tile.cs

Tile.cs

Caricato da:
Scarica il programma completo

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Windows.Forms;
  7.  
  8. namespace tileSlide
  9. {
  10.         /// <summary>
  11.         /// This class builds ta control, which will be used
  12.         /// to draw the tiles in the puzzle game.
  13.         /// </summary>
  14.         public class ctlTile : System.Windows.Forms.UserControl
  15.         {
  16.                 #region Private filds
  17.                 private Point imagePoint;
  18.                 private System.Windows.Forms.Button imageBase;
  19.                 private System.Windows.Forms.PictureBox tilePic;
  20.                 private int tindex;
  21.                 #endregion Private filds
  22.  
  23.                 #region Public Properties
  24.                 //Public Properties
  25.                 public int tIndex
  26.                 {
  27.                         get{return tindex;}
  28.                 }
  29.  
  30.                 public Size tImageSize
  31.                 {
  32.                         get{return this.tilePic.Size;}
  33.                 }
  34.                 #endregion Public Properties
  35.  
  36.  
  37.                 /// <summary>
  38.                 /// Required designer variable.
  39.                 /// </summary>
  40.                 private System.ComponentModel.Container components = null;
  41.  
  42.                 #region Contructor and Dispose
  43.                 // Constructor for the control
  44.                 public ctlTile(int tWidth, int tHeight,int index)
  45.                 {
  46.                         //Tile's Index
  47.                         tindex = index;
  48.                        
  49.                         //Disable control so parent form cann handle its key and mouse
  50.                         //events
  51.                         Enabled = false;
  52.  
  53.                         // This call is required by the Windows.Forms Form Designer.
  54.                         InitializeComponent();
  55.  
  56.                         //Image Base and Imgae Fixation Here
  57.                         if ((tWidth < 32 || tWidth > 96) || ( tHeight <32 || tHeight > 96))
  58.                         {
  59.                                 this.Size = new Size(64,64);
  60.                                 tWidth = 64;
  61.                                 tHeight = 64;
  62.                         }
  63.                         else this.Size = new Size(tWidth, tHeight);
  64.                        
  65.                         imageBase.Location = new Point(0,0);
  66.                         imageBase.Size = new Size(tWidth,tHeight);
  67.                         tilePic.Location = new Point(1,1);
  68.                         tilePic.Size = new Size(tWidth - 2,tHeight - 2);
  69.                         tilePic.Image = null;
  70.                 }
  71.  
  72.                 /// <summary>
  73.                 /// Clean up any resources being used.
  74.                 /// </summary>
  75.                 protected override void Dispose( bool disposing )
  76.                 {
  77.                         if( disposing )
  78.                         {
  79.                                 if(components != null)
  80.                                 {
  81.                                         components.Dispose();
  82.                                 }
  83.                         }
  84.                         base.Dispose( disposing );
  85.                 }
  86.  
  87.                 #region Component Designer generated code
  88.                 /// <summary>
  89.                 /// Required method for Designer support - do not modify
  90.                 /// the contents of this method with the code editor.
  91.                 /// </summary>
  92.                 private void InitializeComponent()
  93.                 {
  94.                         this.imageBase = new System.Windows.Forms.Button();
  95.                         this.tilePic = new System.Windows.Forms.PictureBox();
  96.                         this.SuspendLayout();
  97.                         //
  98.                         // imageBase
  99.                         //
  100.                         this.imageBase.BackColor = System.Drawing.Color.DarkOliveGreen;
  101.                         this.imageBase.Enabled = false;
  102.                         this.imageBase.FlatStyle = System.Windows.Forms.FlatStyle.System;
  103.                         this.imageBase.Location = new System.Drawing.Point(1, 1);
  104.                         this.imageBase.Name = "imageBase";
  105.                         this.imageBase.Size = new System.Drawing.Size(62, 62);
  106.                         this.imageBase.TabIndex = 0;
  107.                         //
  108.                         // tilePic
  109.                         //
  110.                         this.tilePic.BackColor = System.Drawing.Color.OliveDrab;
  111.                         this.tilePic.Location = new System.Drawing.Point(2, 2);
  112.                         this.tilePic.Name = "tilePic";
  113.                         this.tilePic.Size = new System.Drawing.Size(60, 60);
  114.                         this.tilePic.TabIndex = 1;
  115.                         this.tilePic.TabStop = false;
  116.                         this.tilePic.Click += new System.EventHandler(this.tilePic_Click);
  117.                         this.tilePic.Paint += new System.Windows.Forms.PaintEventHandler(this.TilePic_Paint);
  118.                         //
  119.                         // ctlTile
  120.                         //
  121.                         this.Controls.Add(this.tilePic);
  122.                         this.Controls.Add(this.imageBase);
  123.                         this.Name = "ctlTile";
  124.                         this.Size = new System.Drawing.Size(64, 64);
  125.                         this.ResumeLayout(false);
  126.  
  127.                 }
  128.                 #endregion
  129.  
  130.                 #endregion Contructor and Dispose
  131.  
  132.                 #region Tile Picture
  133.                 //Here the tile imgae is declared painted on the tile
  134.                 public void tilePicture(Image tImage, Point StartPt)
  135.                 {
  136.                         tilePic.Image = tImage;
  137.             imagePoint = StartPt;
  138.                 }
  139.                 #endregion Tile Picture
  140.  
  141.                 #region Repaint Tile
  142.        
  143.                 private void TilePic_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  144.                 {
  145.                         if (tilePic.Image != null)
  146.                         {
  147.                                 Graphics g = e.Graphics;
  148.                                 g.DrawImage(tilePic.Image, new Rectangle(new Point(0,0),new Size(tilePic.Width,tilePic.Height)),
  149.                                         new Rectangle(imagePoint,new Size(tilePic.Width,tilePic.Height)),GraphicsUnit.Pixel);
  150.                         }
  151.                 }
  152.                 #endregion Repaint Tile
  153.  
  154.                 private void tilePic_Click(object sender, System.EventArgs e)
  155.                 {
  156.                
  157.                 }
  158.         }
  159. }