help with tabControl confusion please?

  • Thread starter Thread starter cdj
  • Start date Start date
C

cdj

Hi all,

I've got a tabControl, initially with one tabPage, along with two
buttons, one to add another tabPage, and one to delete the current
(selected) tabPage.

On each tabPage, when it is created, is an pictureBox.

Other stuff on the form leads to the creation of a graphic, say
myImage, which I would like to assign to the pictureBox.Image property
of the pictureBox on the currently selected tabPage.

I've tried all sorts of things (and learned a lot about the tabControl
class - lol), but I can't for the life of me figure out how to refer
to: "the pictureBox on the currently-selected tabPage of the
tabControl".

This is a let's-learn-C# project for myself, so any help would be much
appreciated.

Thanks in advance,

cdj
 
Are you talking about this?
======================================================
private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

tabControl1.SelectedTab.Controls.Add(pictureBox1);

}

==================================================================

Now in this code if you want to change the image of picture box just change
it before using it.
 
ISMAILRAJPUT said:
Are you talking about this?
======================================================
private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

tabControl1.SelectedTab.Controls.Add(pictureBox1);

}

==================================================================

Not quite - I've already put pictureBoxes on the newly-made
tabPages......... What I need to do now is put a graphic, say myImage, into
the myPicBox.Image property of the pictureBox of the currently selected
tabPage. In other words, I just need a statement of the following form:

(pictureBox control on the currently selected tabPage on the
tabControl).Image = myImage;

Of course, the stuff in parentheses isn't valid c#, which is why I'm
here.... I just don't know how to refer to a control I've created
programmatically.... :(

I've been looking thru the tabControl class library, but I just don't see
what I use from there to make a statement such as the above.

Somewhat more generally, I was hoping to make a variable, to wit
currentPictureBox, which would be updated with the pictureBox on the current
tabPage according to the SelectedIndexChanged event.

thanks for your response though,

cdj
 
here is another way
=========================================================

private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)

{

pictureBox1.Image = System.Drawing.Image.FromFile("C:\\goldepic2.jpg");

tabControl1.SelectedTab.Controls.Add(pictureBox1);

}

=====================================================================
 
Back
Top