How to get control under a TabControl

Class library usage, coding and language questions.
bk
Posts: 1
Joined: Thu Jan 18, 2007 1:33 am

How to get control under a TabControl

Post by bk » Thu Jan 18, 2007 1:40 am

Hi,

I have a tab control that contain a number of tabs. Each tab contains a form and each of the form contains some controls(button, combo, etc...). Would someone please show me how do I get to a specific control(e.g a combobox) in a form under a certain tab?

I am using C# for my application and RanorexNet for testing.

Thanks in advance
bk

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Thu Jan 18, 2007 11:30 pm

Normally you can find the controls of a tab control also with the form find functions, there are in the client area:

Code: Select all

CheckBox checkBoxInTab = form.FindCheckBox("checkBox3");
In V1.1.0, you will be able to find a child control in another control.

In V1.0.0 you can read all controls of a tab control as follows:

If you have the professional version:

Code: Select all

// Get all controls of the tab
Form tabForm = new Form(tabControl.Handle);
tabForm.GetControls();
foreach (Control control in tabForm.Controls)
{
    IntPtr handle = control.Handle;
    Point location = control.Location;
    Size size = control.Size;
    String text = control.Text;
    Console.WriteLine("Handle={0} Location={1} Text={2}", handle, location, text);
}
If not, than you can read all controls of the form and filter one:

Code: Select all

// Get all controls of the form
form.GetControls();
foreach (Control control in form.Controls)
{
    IntPtr handle = control.Handle;
    Point location = control.Location;
    Size size = control.Size;
    String text = control.Text;
    Console.WriteLine("Handle={0} Location={1} Text={2}", handle, location, text);
}
Please read also the following topic:
This works with elements, you can do the same in C#.

Access to control in Tabcontrol

Jenö Herget
Ranorex Team