wizardrycon
July 13th, 2006, 06:41 PM
Hi,
I am fairly new to programming with .NET and have ran into a problem which I can not figure out.
I am trying to create a grid using buttons. This will become an interface for the popular Sudoku game.
I have ran test's and the controls are being added (I verified by checking the contains method return for each control) but the only visible buttons are in the first quadrant (separated into 9 Panels).
Any idea why this is not painting the other buttons? I am stumped!
------------------------------------------------------------------------------------------
Also if anyone knows how I can create the form controls so they automatically size to match the size of the form (i.e. the boxes will grow as the form is stretched out and shrink when pulled back in) I would like to implement that functionality as well.
And since I am new to this environment, any constructive criticism or ways this could be improved would be greatly appreciated.
Thanks!
OUTPUT:
http://www.iwebnow.com/SudokuFormScreen.gif
SOURCE:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace SudokuGridFormA
{
public class SudokuGridForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel [,] panel = new Panel[3,3];
private System.Windows.Forms.Button [,] GridBtn = new Button[9,9];
private int _tabindexnum = 0;
public int TabIndexNum
{
get {return(_tabindexnum++);}
}
public SudokuGridForm()
{
this.SuspendLayout();
this.groupBox1 = new System.Windows.Forms.GroupBox();
for(int y = 0; y<3; y++)
for(int x = 0; x<3; x++)
{
this.AddPanel(x,y,x*3,2+(x*3),y*3,2+(y*3));
this.groupBox1.Controls.Add(this.panel[x,y]);
}
this.groupBox1.Location = new System.Drawing.Point(16, 24);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(336, 344);
this.groupBox1.TabIndex = this.TabIndexNum;
this.groupBox1.TabStop = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(368, 382);
this.Controls.Add(this.groupBox1);
this.Name = "SudokuGridForm";
this.Text = "SudokuGridForm";
this.ResumeLayout(true);
}
private void AddPanel(int panelNumX, int panelNumY, int x1, int x2, int y1, int y2)
{
this.panel[panelNumX,panelNumY] = new System.Windows.Forms.Panel();
this.panel[panelNumX,panelNumY].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel[panelNumX,panelNumY].Location = new System.Drawing.Point(24+(panelNumX*96),32+(panelNumY*96));
this.panel[panelNumX,panelNumY].Name = "panel" + panelNumX.ToString()+panelNumY.ToString();
this.panel[panelNumX,panelNumY].Size = new System.Drawing.Size(96, 96);
this.panel[panelNumX,panelNumY].TabIndex = this.TabIndexNum;
for(int y=y1; y<=y2; y++)
for(int x=x1; x<=x2; x++)
{
this.GridBtn[x,y] = new System.Windows.Forms.Button();
this.panel[panelNumX,panelNumY].Controls.Add(this.GridBtn[x,y]);
this.GridBtn[x,y].Location = new System.Drawing.Point(0+(x*32), 0+(y*32));
this.GridBtn[x,y].Name = "GridBtn"+panelNumX.ToString()+panelNumY.ToString()+x.ToString()+y.ToString();
this.GridBtn[x,y].Size = new System.Drawing.Size(32, 32);
this.GridBtn[x,y].Text = panelNumX.ToString()+","+panelNumY.ToString()+x.ToString()+","+y.ToString();
this.GridBtn[x,y].TabIndex = this.TabIndexNum;
}
}
[STAThread]
static void Main()
{
Application.Run(new SudokuGridForm());
}
}
}
I am fairly new to programming with .NET and have ran into a problem which I can not figure out.
I am trying to create a grid using buttons. This will become an interface for the popular Sudoku game.
I have ran test's and the controls are being added (I verified by checking the contains method return for each control) but the only visible buttons are in the first quadrant (separated into 9 Panels).
Any idea why this is not painting the other buttons? I am stumped!
------------------------------------------------------------------------------------------
Also if anyone knows how I can create the form controls so they automatically size to match the size of the form (i.e. the boxes will grow as the form is stretched out and shrink when pulled back in) I would like to implement that functionality as well.
And since I am new to this environment, any constructive criticism or ways this could be improved would be greatly appreciated.
Thanks!
OUTPUT:
http://www.iwebnow.com/SudokuFormScreen.gif
SOURCE:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace SudokuGridFormA
{
public class SudokuGridForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Panel [,] panel = new Panel[3,3];
private System.Windows.Forms.Button [,] GridBtn = new Button[9,9];
private int _tabindexnum = 0;
public int TabIndexNum
{
get {return(_tabindexnum++);}
}
public SudokuGridForm()
{
this.SuspendLayout();
this.groupBox1 = new System.Windows.Forms.GroupBox();
for(int y = 0; y<3; y++)
for(int x = 0; x<3; x++)
{
this.AddPanel(x,y,x*3,2+(x*3),y*3,2+(y*3));
this.groupBox1.Controls.Add(this.panel[x,y]);
}
this.groupBox1.Location = new System.Drawing.Point(16, 24);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(336, 344);
this.groupBox1.TabIndex = this.TabIndexNum;
this.groupBox1.TabStop = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(368, 382);
this.Controls.Add(this.groupBox1);
this.Name = "SudokuGridForm";
this.Text = "SudokuGridForm";
this.ResumeLayout(true);
}
private void AddPanel(int panelNumX, int panelNumY, int x1, int x2, int y1, int y2)
{
this.panel[panelNumX,panelNumY] = new System.Windows.Forms.Panel();
this.panel[panelNumX,panelNumY].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel[panelNumX,panelNumY].Location = new System.Drawing.Point(24+(panelNumX*96),32+(panelNumY*96));
this.panel[panelNumX,panelNumY].Name = "panel" + panelNumX.ToString()+panelNumY.ToString();
this.panel[panelNumX,panelNumY].Size = new System.Drawing.Size(96, 96);
this.panel[panelNumX,panelNumY].TabIndex = this.TabIndexNum;
for(int y=y1; y<=y2; y++)
for(int x=x1; x<=x2; x++)
{
this.GridBtn[x,y] = new System.Windows.Forms.Button();
this.panel[panelNumX,panelNumY].Controls.Add(this.GridBtn[x,y]);
this.GridBtn[x,y].Location = new System.Drawing.Point(0+(x*32), 0+(y*32));
this.GridBtn[x,y].Name = "GridBtn"+panelNumX.ToString()+panelNumY.ToString()+x.ToString()+y.ToString();
this.GridBtn[x,y].Size = new System.Drawing.Size(32, 32);
this.GridBtn[x,y].Text = panelNumX.ToString()+","+panelNumY.ToString()+x.ToString()+","+y.ToString();
this.GridBtn[x,y].TabIndex = this.TabIndexNum;
}
}
[STAThread]
static void Main()
{
Application.Run(new SudokuGridForm());
}
}
}