Michael
Michael

Reputation: 13636

How to get child control?

I have TabControl that contain 4 subTabs.

enter image description here

Each of the tab contain picture box cotrol.

I need to get the picture box control of the selected Tab Control.

Any idea how to implement it?

Upvotes: 1

Views: 5982

Answers (3)

CharithJ
CharithJ

Reputation: 47570

var pictureBox = tabControl1.SelectedTab.Controls.Cast<Control>()
                                .FirstOrDefault(x => x is PictureBox);

Upvotes: 1

Stephen King
Stephen King

Reputation: 836

You can find the control via

[1] http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.find%28VS.90%29.aspx

Once you find the control, you can then cast it to what you are expecting example:

[2] How to get control(s) from TabPage in C#?

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460288

Perhaps

var picBox = TabControl1.SelectedTab.Controls.OfType<PictureBox>().First();

Upvotes: 14

Related Questions