Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i make swap between 2 buttons that contain images
p.s. i made 2 array 2D "memory game"
i put 24 buttons that contain different pictures and above them another 24 buttons that contain "Question mark picture"

System.Windows.Forms.Button[,] m = new
System.Windows.Forms.Button[4, 6];
m[0, 0] = b1;
m[0, 1] = b2;
m[0, 2] = b3;
m[0, 3] = b4;
m[0, 4] = b5;
m[0, 5] = b6;
m[1, 0] = b7;
m[1, 1] = b8;
m[1, 2] = b9;
m[1, 3] = b9;
m[1, 4] = b11;
m[1, 5] = b12;
m[2, 0] = b13;
m[2, 1] = b14;
m[2, 2] = b15;
m[2, 3] = b16;
m[2, 4] = b17;
m[2, 5] = b18;
m[3, 0] = b19;
m[3, 1] = b20;
m[3, 2] = b21;
m[3, 3] = b22;
m[3, 4] = b23;
m[3, 5] = b24;

"buttons that above"

System.Windows.Forms.Button[,] n = new
System.Windows.Forms.Button[4, 6];
n[0, 0] = bt1;
n[0, 1] = bt2;
n[0, 2] = bt3;
n[0, 3] = bt4;
n[0, 4] = bt5;
n[0, 5] = bt6;
n[1, 0] = bt7;
n[1, 1] = bt8;
n[1, 2] = bt9;
n[1, 3] = bt9;
n[1, 4] = bt11;
n[1, 5] = bt12;
n[2, 0] = bt13;
n[2, 1] = bt14;
n[2, 2] = bt15;
n[2, 3] = bt16;
n[2, 4] = bt17;
n[2, 5] = bt18;
n[3, 0] = bt19;
n[3, 1] = bt20;
n[3, 2] = bt21;
n[3, 3] = bt22;
n[3, 4] = bt23;
n[3, 5] = bt24;
Posted

Generally speaking, a swap function needs a temporary variable, for instance
void swap(ref Button b1, ref Button b2)
{
  Button tmp = b1;
  b1 = b2;
  b2 = tmp; 
}


However, I suspect the above is not what you intended... :rolleyes:


[added]
Hi, Mr. Univoter, don't you like swap functions?
BTW: Happy new 11111111111111111111111 year!
[/added]
 
Share this answer
 
v4
Swap the images, not the buttons.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900