asp.net - C# Drawing Chess Board -
i'm trying draw 8x8 chess board using c#. here's first attempt draw it. won't draw board , haven't found i'm missing.
public void form1_load(object sender, eventargs e) { bitmap bm = new bitmap(8 * 100, 8 * 100); graphics g = graphics.fromimage(bm); color color1, color2; (int = 0; < 8; i++) { if (i % 2 == 0) { color1 = color.black; color2 = color.white; } else { color1 = color.white; color2 = color.black; } solidbrush blackbrush = new solidbrush(color1); solidbrush whitebrush = new solidbrush(color2); (int j = 0; j < 8; j++) { if (j % 2 == 0) g.fillrectangle(blackbrush, * 100, j * 100, 100, 100); else g.fillrectangle(whitebrush, * 100, j * 100, 100, 100); } } g.drawimage(bm, 150, 200); }
add backgroundimage = bm;
bottom of code.
you drawing board fine, not displaying bitmap...
edit: im not sure if you're interested, rewrote code.
bitmap bm = new bitmap(800, 800); using (graphics g = graphics.fromimage(bm)) using (solidbrush blackbrush = new solidbrush(color.black)) using (solidbrush whitebrush = new solidbrush(color.white)) { (int = 0; < 8; i++) { (int j = 0; j < 8; j++) { if ((j % 2 == 0 && % 2 == 0) || (j % 2 != 0 && % 2 != 0)) g.fillrectangle(blackbrush, * 100, j * 100, 100, 100); else if ((j % 2 == 0 && % 2 != 0) || (j % 2 != 0 && % 2 == 0)) g.fillrectangle(whitebrush, * 100, j * 100, 100, 100); } } backgroundimage = bm; }
also project if want make chess game: http://www.codeproject.com/articles/20736/c-c-cli-micro-chess-huo-chess
Comments
Post a Comment