Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding a Panel to a Form
    primarykey
    data
    text
    <p>I am making a Seabattle game where the Ships are hidden in a panel with a label array. This label array needs to have more or less rows and columns depending on the chosen difficulty level.</p> <p>So I made a new class "Gameboard" where the Panel and the label array is defined. The problem is that I cant figure out how to bind the panel I make in this class to the Form..</p> <pre><code>namespace SO_S2_Programmeren_Groep08 { class GameBoard{ Panel pnlSlagveld; private Label[,] lblArray; private int row; private int column; public Label[,] LblArray { get { return lblArray; } set { lblArray = value; } } public int Row { get { return row; } set { row = value; } } public int Column { get { return column; } set { column = value; } } public GameBoard(int row, int column) { this.row = row; this.column = column; CreateLableArray(row, column); } public GameBoard() { this.row = 7; this.column = 9; CreateLableArray(row, column); } private void CreateLableArray(int ingrow, int ingcolumn) { pnlBattleField = new System.Windows.Forms.Panel(); lblArray = new Label[ingrow, ingcolumn]; int xpos = 0; int ypos = 0; for (int row = 0; row &lt; ingrow; row++) { for (int column = 0; column &lt; ingcolumn; column++) { lblArray[row, column] = new Label(); lblArray[row, column].Left = xpos; lblArray[row, column].Top = ypos; lblArray[row, column].Width = 50; lblArray[row, column].Height = 50; lblArray[row, column].Tag = (char)('A' + column) + (row + 1).ToString(); lblArray[row, column].Click += lblArray_Click; lblArray[row, column].BackColor = Color.Aqua; lblArray[row, column].BorderStyle = BorderStyle.FixedSingle; pnlBattlefield.Controls.Add(lblArray[row, column]); xpos += lblArray[row, column].Width; } ypos += lblArray[row, 0].Width; xpos = 0; } }/*CreateLableArray*/ private void lblArray_Click(object sender, EventArgs e) { MessageBox.Show("Clicked on Label " + ((Label)sender).Tag.ToString()); } } </code></pre> <p>}</p> <p>If you'd like to see more classes please ask!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload