c# - Dynamically programming a grid consisting of 64 buttons (8x8) -
i'm trying create chess game purely learning c# , chess. start off with, create 8x8 grid of buttons through code rather designer. save me hard coding each button individually.
a button array seem way start have no idea how implement this.
int buttonwidth = 40; int buttonheight = 40; int distance = 20; int start_x = 10; int start_y = 10; (int x = 0; x < 8; x++) { (int y = 0; y < 8; y++) { button tmpbutton = new button(); tmpbutton.top = start_x + (x * buttonheight + distance); tmpbutton.left = start_y + (y * buttonwidth + distance); tmpbutton.width = buttonwidth; tmpbutton.height = buttonheight; tmpbutton.text = "x: " + x.tostring() + " y: " + y.tostring(); // possible add buttonclick event etc.. this.controls.add(tmpbutton); } }
Comments
Post a Comment