Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 2.08 KB

add-content-to-a-text-box-using-ui-automation.md

File metadata and controls

30 lines (23 loc) · 2.08 KB
title description ms.date dev_langs helpviewer_keywords ms.topic
Add Content to a Text Box Using UI Automation
See an example of how to add content into a single-line text box by using Microsoft UI Automation in .NET.
03/30/2017
csharp
vb
adding content to text boxes
text boxes, adding content
UI Automation, adding content to text boxes
how-to

Add Content to a Text Box Using UI Automation

Note

This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the xref:System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.

This topic contains example code that demonstrates how to use Microsoft UI Automation to insert text into a single-line text box. An alternate method is provided for multi-line and rich text controls where UI Automation is not applicable. For comparison purposes, the example also demonstrates how to use Win32 methods to accomplish the same results.

Example

The following example steps through a sequence of text controls in a target application. Each text control is tested to see if a xref:System.Windows.Automation.ValuePattern object can be obtained from it using the xref:System.Windows.Automation.AutomationElement.TryGetCurrentPattern%2A method. If the text control does support xref:System.Windows.Automation.ValuePattern, the xref:System.Windows.Automation.ValuePattern.SetValue%2A method is used to insert a user-defined string into the text control. Otherwise, the xref:System.Windows.Forms.SendKeys.SendWait%2A?displayProperty=nameWithType method is used.

[!code-csharpInsertText#InsertText] [!code-vbInsertText#InsertText]

See also