|
■No56800 (まさと さん) に返信
> VB.NETで開発していますが、画面のプロパティの適用ボタンを疑似的に押したいのですが、どのように記述すればよろしいでしょうか?宜しくお願いいたします。
『画面のプロパティ』というタイトルのダイアログを探しだし、
その中の適用ボタンを押すようにしてみました。VB2008 + WinXP で動作確認。
Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim aoForm As AccessibleObject = Me.AccessibilityObject
Dim aoDesktop As AccessibleObject = aoForm.Parent.Parent
Dim aoChild As AccessibleObject = FindFirst(aoDesktop, _
Function(ao) ao.Role = AccessibleRole.Window _
AndAlso ao.Name = "画面のプロパティ")
Dim aoDialog As AccessibleObject = FindFirst(aoChild, _
Function(ao) ao.Role = AccessibleRole.Dialog)
Dim aoButton As AccessibleObject = FindFirst(aoDialog, _
Function(ao) ao.Role = AccessibleRole.Window _
AndAlso ao.Name Like "適用*" _
AndAlso UCase(ao.KeyboardShortcut) = "ALT+A")
Dim aoPush As AccessibleObject = FindFirst(aoButton, _
Function(ao) ao.Role = AccessibleRole.PushButton)
If aoPush IsNot Nothing Then
aoPush.DoDefaultAction()
End If
End Sub
' Accessibility.dll を参照設定する必要があります。
Public Function FindFirst(ByVal base As AccessibleObject, _
ByVal condition As Func(Of AccessibleObject, Boolean)) As AccessibleObject
If base Is Nothing Then
Return Nothing
End If
Dim child As AccessibleObject = base.Navigate(AccessibleNavigation.FirstChild)
Do Until child Is Nothing
If condition(child) Then
Return child
Else
child = child.Navigate(AccessibleNavigation.Next)
End If
Loop
Return Nothing
End Function
End Class
|