PopupEventArgs.AssociatedControl Właściwość

Definicja

Pobiera kontrolkę, dla której ToolTip jest rysowany.

public:
 property System::Windows::Forms::Control ^ AssociatedControl { System::Windows::Forms::Control ^ get(); };
public System.Windows.Forms.Control AssociatedControl { get; }
public System.Windows.Forms.Control? AssociatedControl { get; }
member this.AssociatedControl : System.Windows.Forms.Control
Public ReadOnly Property AssociatedControl As Control

Wartość właściwości

Element Control skojarzony z elementem ToolTiplub null , jeśli etykietka narzędzia nie jest skojarzona z kontrolką.

Przykłady

W poniższym przykładzie kodu pokazano użycie tego elementu członkowskiego. W tym przykładzie program obsługi zdarzeń zgłasza wystąpienie ToolTip.Popup zdarzenia. Ten raport pomaga dowiedzieć się, kiedy wystąpi zdarzenie, i może pomóc w debugowaniu. Aby zgłosić wiele zdarzeń lub często występujących zdarzeń, rozważ zastąpienie MessageBox.Show komunikatu ciągiem Console.WriteLine lub dołączenie go do wielowierszowego TextBoxelementu .

Aby uruchomić przykładowy kod, wklej go w projekcie zawierającym wystąpienie typu ToolTip o nazwie ToolTip1. Następnie upewnij się, że program obsługi zdarzeń jest skojarzony ze zdarzeniem ToolTip.Popup .

private void ToolTip1_Popup(Object sender, PopupEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "AssociatedWindow", e.AssociatedWindow );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "AssociatedControl", e.AssociatedControl );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "IsBalloon", e.IsBalloon );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ToolTipSize", e.ToolTipSize );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Popup Event" );
}
Private Sub ToolTip1_Popup(sender as Object, e as PopupEventArgs) _ 
     Handles ToolTip1.Popup

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "AssociatedWindow", e.AssociatedWindow)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "AssociatedControl", e.AssociatedControl)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "IsBalloon", e.IsBalloon)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ToolTipSize", e.ToolTipSize)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancel", e.Cancel)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"Popup Event")

End Sub

Uwagi

Ponieważ można skojarzyć ToolTip z wieloma kontrolkami za pomocą ToolTip.SetToolTip metody , możesz użyć AssociatedControl właściwości , aby określić, z którą kontrolką Draw jest skojarzone zdarzenie. Jest to przydatne, jeśli chcesz wykonać różne dostosowania etykietki narzędzi na podstawie skojarzonej kontrolki.

Dotyczy

Zobacz też