UI 자동화 공급자에서 이벤트 발생
참고 |
---|
이 문서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI Automation 클래스를 사용하려는 .NET Framework 개발자를 위해 작성되었습니다.UI Automation에 대한 최신 정보는 Windows Automation API: UI Automation을 참조하십시오. |
이 항목에는 UI 자동화 공급자에서 이벤트를 발생시키는 방법을 보여 주는 예제 코드가 있습니다.
예제
다음 예제의 경우 사용자 지정 단추 컨트롤 구현에서 UI Automation 이벤트가 발생합니다. 이 구현을 통해 UI 자동화 클라이언트 응용 프로그램이 단추 클릭을 시뮬레이션할 수 있습니다.
필요 없는 처리 작업을 방지하기 위해 예제에서는 ClientsAreListening을 확인하여 이벤트를 발생시킬지 여부를 결정합니다.
''' <summary>
''' Responds to a button click, regardless of whether it was caused by a
''' mouse or keyboard click or by InvokePattern.Invoke.
''' </summary>
Private Sub OnCustomButtonClicked()
'' TODO Perform program actions invoked by the control.
'' Raise an event.
If AutomationInteropProvider.ClientsAreListening Then
Dim args As AutomationEventArgs = _
New AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent)
AutomationInteropProvider.RaiseAutomationEvent( _
InvokePatternIdentifiers.InvokedEvent, Me, args)
End If
End Sub
/// <summary>
/// Responds to a button click, regardless of whether it was caused by a mouse or
/// keyboard click or by InvokePattern.Invoke.
/// </summary>
private void OnCustomButtonClicked()
{
// TODO Perform program actions invoked by the control.
// Raise an event.
if (AutomationInteropProvider.ClientsAreListening)
{
AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
}
}