Sunday, October 16, 2005 - 00:27

PictureBox in C#2.0 Beta

I'm having an odd problem with PictureBoxes in C# 2.0. Specifically, I'm having a problem assigning them at runtime (not changing their image - that's fine).

This is best illustrated using code snippets.

This works (MapPB and pictureBox1 are both PictureBoxes):

private void button2_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
MapPB.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
}

This doesn't - MapPB just stays empty:
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
MapPB = pictureBox1;
}

And the same for this:
private void button2_Click(object sender, EventArgs e)
{
MapPB = pictureBox1;
pictureBox1.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
}
and of course this:
private void button2_Click(object sender, EventArgs e)
{
MapPB = pictureBox1;
pictureBox1.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
MapPB.ImageLocation = @"D:\Misc\cthulhusmall.jpg";
}


It's as if it's okay to change the properties of a PictureBox, but not to assign another PictureBox to it :-S Once you do that, you're screwed, no matter what you try to do to itafterwards. I just can't figure out why.

I've never really used PictureBoxes before, so I don't know if they work the same way in 1.0 (and something to 1 on a Saturday night/Sunday morning, I'm not too eager to write some code to try it out); and I don't know if this is by design in 2.0 or a bug, seeing as it is a beta release.

If you have any ideas or solutions, please leave a comment - this is seriously going to impact the design of my app, if I can't assign PictureBoxes at runtime :-(

Update: as a friend pointed out a couple of minutes after I posted this, of course it won't work, since the control that is drawn is the one in the form's control collection, and not MapPB. So changing the object that MapPB points to is not going to change the control that's drawn.

Labels:

2 Comments:

At 16/10/05 00:36, Anonymous Anonymous said...

This comment has been removed by a blog administrator.

 
At 16/10/05 00:36, Anonymous Anonymous said...

This comment has been removed by a blog administrator.

 

Post a Comment

<< Home