TogglePattern.Toggle Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menelusuri status tombol dari AutomationElement.
public:
void Toggle();
public void Toggle ();
member this.Toggle : unit -> unit
Public Sub Toggle ()
Contoh
Dalam contoh berikut, TogglePattern pola kontrol diperoleh dari AutomationElement dan kemudian digunakan untuk mengalihkan AutomationElement.
///--------------------------------------------------------------------
/// <summary>
/// Obtains a TogglePattern control pattern from an automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A TogglePattern object.
/// </returns>
///--------------------------------------------------------------------
private TogglePattern GetTogglePattern(AutomationElement targetControl)
{
TogglePattern togglePattern = null;
try
{
togglePattern =
targetControl.GetCurrentPattern(TogglePattern.Pattern)
as TogglePattern;
}
catch (InvalidOperationException)
{
// object doesn't support the TogglePattern control pattern
return null;
}
return togglePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a TogglePattern control pattern from an automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A TogglePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetTogglePattern( _
ByVal targetControl As AutomationElement) As TogglePattern
Dim togglePattern As TogglePattern = Nothing
Try
togglePattern = DirectCast( _
targetControl.GetCurrentPattern(togglePattern.Pattern), _
TogglePattern)
Catch
' object doesn't support the TogglePattern control pattern
Return Nothing
End Try
Return togglePattern
End Function 'GetTogglePattern
///--------------------------------------------------------------------
/// <summary>
/// Calls the TogglePattern.Toggle() method for an associated
/// automation element.
/// </summary>
/// <param name="togglePattern">
/// The TogglePattern control pattern obtained from
/// an automation element.
/// </param>
///--------------------------------------------------------------------
private void ToggleElement(TogglePattern togglePattern)
{
try
{
togglePattern.Toggle();
}
catch (InvalidOperationException)
{
// object is not able to perform the requested action
return;
}
}
'''--------------------------------------------------------------------
''' <summary>
''' Calls the TogglePattern.Toggle() method for an associated
''' automation element.
''' </summary>
''' <param name="togglePattern">
''' The TogglePattern control pattern obtained from
''' an automation element.
''' </param>
'''--------------------------------------------------------------------
Private Sub ToggleElement(ByVal togglePattern As TogglePattern)
Try
togglePattern.Toggle()
Catch
' object is not able to perform the requested action
Return
End Try
End Sub
Keterangan
Kontrol akan berputar melalui ToggleState dalam urutan ini: On, Off dan, jika didukung, Indeterminate.
Berlaku untuk
Berkolaborasi dengan kami di GitHub
Sumber untuk konten ini dapat ditemukan di GitHub, yang juga dapat Anda gunakan untuk membuat dan meninjau masalah dan menarik permintaan. Untuk informasi selengkapnya, lihat panduan kontributor kami.