Creating and displaying a two dimensional array of picturebox

A

Ahmed El-Daly

Hi,

The code attached seems to create the pictureboxes but they fail to
display on the form. The items displayed are supposed to be cards from
cards.dll. The code works fine if I provide the hdc of the form
itself, or of a PictureBox that I create myself in the designer.

PictureBox[,] CardFrame = new PictureBox[4, 13];
//PictureBox pictureBox1 = new PictureBox();

private void button1_Click(object sender, System.EventArgs e)
{
int ypos;
Cards yarab = new Cards();
IntPtr hdc;
Graphics hdcobject;
for (int z=0; z<4; z++)
{
ypos = 0;
for (int y=0; y<13; y++)
{
this.CardFrame[z,y] = new PictureBox();
//this.CardFrame[z,y].Visible = true;
/*this.pictureBox1.Size = new Size(50,100);
this.pictureBox1.BorderStyle = BorderStyle.Fixed3D;*/
hdcobject = this.CardFrame[z,y].CreateGraphics();
hdc = hdcobject.GetHdc();
yarab.DrawCard(hdc, 0, 0, yarab.PlayerHand[z, y], 0, 0);
hdcobject.ReleaseHdc(hdc);
ypos += 30;
this.CardFrame[z,y].Location = new Point(z * 100, ypos);
this.Controls.Add(this.CardFrame[z,y]);
//MessageBox.Show((Convert.ToString(this.Controls.Count)));
if(y==5)
MessageBox.Show("5");
else if(y==10)
MessageBox.Show("10");
}
}
//this.Controls.AddRange(new Control[]{this.CardFrame});
MessageBox.Show("done!!");
//this.pictureBox1.CreateGraphics().ReleaseHdc(hdc);
//yarab.DrawCard(hdc, 0, 0, 22, 0, 0); works fine!
//yarab.DrawCard(hdc, 0, 100, 22, 60, 0); this is not working yet!
//yarab.DrawCard(hdc, 0, 200, 22, 2, 0); works fine!
}
}
}

Thank you very bery bery much!!
 
A

Ahmed El-Daly

Hi,

I did not receive any responce. Am I posting to the wrong group? If I
am, please lead me to the correct group. If you need any clarification
to the code I provided, I'd be more than happy to provide it. I
thought that this card game would be a good way for me to learn about
c#.

Thanks,
Ahmed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top