Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In <strong><em>WinForms</em></strong> this is very easy ... just grab the WinForms container and then prob the '.Controls' property and iterate over the collection of controls returned.</p> <pre><code> foreach (System.Windows.Forms.Control ctrl in form.Controls) { if (ctrl.Name == "tabPageControl") { // do something with 'tabPageControl object' } { </code></pre> <p>As you can see in WinForms its dead easy to get access at the global container to return a 'ControlCollection' and then iterate through or even deeper if its a panel or something like that. Once you have found what you want are simply building a list of what can be found then do something with your list or your control.</p> <p>In <strong><em>WPF</em></strong>, this is done slightly differenty. I don't have extensive WPF experience but after 15 mins of playing about I came up with this:</p> <pre><code> private void button1_Click(object sender, RoutedEventArgs e) { // cast out Grid object. Grid grd = (Grid) this.Content; // do simple testing to find out what the type is. string s = grd.ToString(); // in VS, in debug mode, hover 'grd.Children' and Smart Tool Tip that pops // it will tell exactly under a 'count' property how many controls there are sitting // on the global container. For me it was just 1, my Button. foreach (UIElement child in grd.Children) { // do some more testing to make sure have got the right control. pref in an If statement but anyhooo. String sss = child.GetType().FullName; // cast out the appropriate type. Button myWpfButton = (Button)child; } } </code></pre> <p>I hope thats enought to get you started.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload