PopupEventArgs.AssociatedControl 属性

定义

获取要为其绘制 ToolTip 的控件。

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

属性值

Control 关联的 ToolTip,如果此工具提示不与控件关联,则为 null

示例

下面的代码示例演示了此成员的用法。 在此示例中,事件处理程序报告事件的发生情况 ToolTip.Popup 。 此报表可帮助你了解事件发生的时间,并可以帮助你进行调试。 若要报告多个事件或频繁发生的事件,请考虑将 MessageBox.Show 替换为 Console.WriteLine 或将消息追加到多行 TextBox

若要运行示例代码,请将其粘贴到包含名为 ToolTip1的 类型的ToolTip实例的项目中。 然后,确保事件处理程序与 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

注解

由于可以通过 方法将 与多个控件相关联ToolTip,因此可以使用 AssociatedControl 属性来确定与事件关联的控件DrawToolTip.SetToolTip 如果要根据关联的控件执行不同的工具提示自定义,这非常有用。

适用于

另请参阅