Working with controls of class Edit and a role of Text

Class library usage, coding and language questions.
creynolds
Posts: 4
Joined: Tue Sep 18, 2007 3:45 pm
Location: USA

Working with controls of class Edit and a role of Text

Post by creynolds » Thu Jun 19, 2008 5:28 pm

I come accross this a lot where I have a control that is of the Edit Class and I'm always setting the focus of the control and then sending keystrokes to the app to add text to the text field of the edit control. Is there a better way? Why isn't there a FindEdit method? Will FindTextBox work for the Edit control? I would like to just set the text of the control to what ever I would like instead of setting focus to the control and then sending keystrokes.

Thanks for you help

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Fri Jun 20, 2008 12:27 pm

Will FindTextBox work for the Edit control?
Yes, you can find an edit box and set/get the text of it as follows:
(See the sample application RanorexVS2005Sample2)

Code: Select all

TextBox textBox = form.FindTextBox("textBox1");
if (textBox != null)
{
    textBox.Focus();
    textBox.Text = "Ranorex";
    text = textBox.Text;
}
Or you can also use the Element class:

Code: Select all

Element fileEditControl = openFileDialog.Element.FindChild(Role.Text,"File name:"); 
if( fileEditControl != null)
    fileEditControl.Value = "D:\\Ranorex\\Bin\\RanorexNet.dll";
Jenö
Ranorex Team