Professional Documents
Culture Documents
Nuevo Codigo
Nuevo Codigo
Text; 08 using System.Windows.Forms; 09 using System.IO; 10 11 namespace pipeworksSlidingPuzzle { 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { PictureBox pb = new PictureBox(); String[] files = Directory.GetFiles(path, "*.jpg"); } private void Form1_Load(object sender, EventArgs e) { AutoSize = true; public mainWindow() { InitializeComponent(); public partial class mainWindow : Form { int rows = 5; int cols = 5; String path ="F:\\IT312\\pipeworksSlidingPuzzle\\pipeworksSlidingPuzzle\\images"; int index = 0, count = 0; Button b1; bool secondClick = false;
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 } } }
pb.Size = new Size(100, 100); pb.SizeMode = PictureBoxSizeMode.StretchImage; pb.Margin = new Padding(0); pb.BorderStyle = BorderStyle.FixedSingle; pb.Location = new Point(c * 100, r * 100); pb.Image = Image.FromFile(files[index]); pb.Tag = index; count++; if (count==2) { index++; count = 0; } Controls.Add(pb);
Button b = new Button(); b.Location = pb.Location; b.Size = pb.Size; b.Tag = pb; Controls.Add(b); b.BringToFront(); b.Click += new EventHandler(Buttonclick);
private void Buttonclick(Object Sender, EventArgs e) { Button b = (Button)Sender; if (secondClick) { b.Hide(); Refresh(); int t1 = (int)((PictureBox)b1.Tag).Tag; int t2 = (int)((PictureBox)b.Tag).Tag; if (t1==t2) { secondClick = false;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 } } } } } else {