This is all I have so far.
tabControl1.TabPages[0].???
I have a PictureBox inside of TabPage1 of my TabControl.
How can I change the image location with code and not the properties pane?
Although the controls appear inside a container (as a TabControl), they're all defined on the form, so there is no need to access them through the container.
Instead of:
tablControl1.TabPages[0].MyContainedControl...
Simply type:
MyContainedControl...
Unless you've set GenerateMember to false on the picture box or you're building the form dynamically you should be able to reference the picture box by its name:
pictureBox1.ImageLocation = "...";
Otherwise, assuming the picture box is the first control in the first tab page you can use the Controls collection:
var picBox = (PictureBox) tabControl1.TabPages[0].Controls[0];
picBox.ImageLocation = "...";
If you know there is exactly one picture box somewhere but you're not sure what page it's on or where on that page it is you can use Linq:
var picBox = tabControl1.TabPages.Cast<Control>()
.SelectMany(page => page.Controls.OfType<PictureBox>())
.First();
picBox.ImageLocation = "...";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With