DrawToolTipEventArgs.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과 연결된 Draw입니다. 도구 설명이 컨트롤과 연결되지 않은 경우 반환 값은 null입니다.

예제

다음 코드 예제에서는 사용자 지정 그리기 방법은 ToolTip합니다. 이 예에서는 만듭니다는 ToolTip 3 연결 Button 컨트롤에 있는 Form. 예제에서는 합니다 OwnerDraw 속성을 true 하 고 처리를 Draw 이벤트입니다. 에 Draw 이벤트 처리기는 ToolTip 는 사용자 지정 단추에 따라 다르게 그려집니다를 ToolTip 나타난 것 처럼 표시 되는 DrawToolTipEventArgs.AssociatedControl 속성.

다음 코드 예제를 사용 하는 방법에 설명 하는 예제는 AssociatedControl 속성입니다. 참조 된 DrawToolTipEventArgs 전체 코드 예제에 대 한 클래스 개요입니다.

   // Handles drawing the ToolTip.
private:
   void toolTip1_Draw( System::Object^ /*sender*/, System::Windows::Forms::DrawToolTipEventArgs^ e )
   {
      // Draw the ToolTip differently depending on which 
      // control this ToolTip is for.
      // Draw a custom 3D border if the ToolTip is for button1.
      if ( e->AssociatedControl == button1 )
      {
         // Draw the standard background.
         e->DrawBackground();
         
         // Draw the custom border to appear 3-dimensional.
         array<Point>^ temp1 = {Point(0,e->Bounds.Height - 1),Point(0,0),Point(e->Bounds.Width - 1,0)};
         e->Graphics->DrawLines( SystemPens::ControlLightLight, temp1 );
         array<Point>^ temp2 = {Point(0,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,0)};
         e->Graphics->DrawLines( SystemPens::ControlDarkDark, temp2 );
         
         // Specify custom text formatting flags.
         TextFormatFlags sf = static_cast<TextFormatFlags>(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter | TextFormatFlags::NoFullWidthCharacterBreak);
         
         // Draw the standard text with customized formatting options.
         e->DrawText( sf );
      }
      // Draw a custom background and text if the ToolTip is for button2.
      else
      
      // Draw a custom background and text if the ToolTip is for button2.
      if ( e->AssociatedControl == button2 )
      {
         // Draw the custom background.
         e->Graphics->FillRectangle( SystemBrushes::ActiveCaption, e->Bounds );
         
         // Draw the standard border.
         e->DrawBorder();
         
         // Draw the custom text.
         // The using block will dispose the StringFormat automatically.
         StringFormat^ sf = gcnew StringFormat;
         try
         {
            sf->Alignment = StringAlignment::Center;
            sf->LineAlignment = StringAlignment::Center;
            sf->HotkeyPrefix = System::Drawing::Text::HotkeyPrefix::None;
            sf->FormatFlags = StringFormatFlags::NoWrap;
            System::Drawing::Font^ f = gcnew System::Drawing::Font( "Tahoma",9 );
            try
            {
               e->Graphics->DrawString( e->ToolTipText, f, SystemBrushes::ActiveCaptionText, e->Bounds, sf );
            }
            finally
            {
               if ( f )
                  delete safe_cast<IDisposable^>(f);
            }

         }
         finally
         {
            if ( sf )
               delete safe_cast<IDisposable^>(sf);
         }
      }
      // Draw the ToolTip using default values if the ToolTip is for button3.
      else if ( e->AssociatedControl == button3 )
      {
         e->DrawBackground();
         e->DrawBorder();
         e->DrawText();
      }
   }
// Handles drawing the ToolTip.
private void toolTip1_Draw(System.Object sender, 
    System.Windows.Forms.DrawToolTipEventArgs e)
{
    // Draw the ToolTip differently depending on which 
    // control this ToolTip is for.
    // Draw a custom 3D border if the ToolTip is for button1.
    if (e.AssociatedControl == button1)
    {
        // Draw the standard background.
        e.DrawBackground();

        // Draw the custom border to appear 3-dimensional.
        e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
            new Point (0, e.Bounds.Height - 1), 
            new Point (0, 0), 
            new Point (e.Bounds.Width - 1, 0)
        });
        e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
            new Point (0, e.Bounds.Height - 1), 
            new Point (e.Bounds.Width - 1, e.Bounds.Height - 1), 
            new Point (e.Bounds.Width - 1, 0)
        });

        // Specify custom text formatting flags.
        TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                             TextFormatFlags.HorizontalCenter |
                             TextFormatFlags.NoFullWidthCharacterBreak;

        // Draw the standard text with customized formatting options.
        e.DrawText(sf);
    }
    // Draw a custom background and text if the ToolTip is for button2.
    else if (e.AssociatedControl == button2)
    {
        // Draw the custom background.
        e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

        // Draw the standard border.
        e.DrawBorder();

        // Draw the custom text.
        // The using block will dispose the StringFormat automatically.
        using (StringFormat sf = new StringFormat())
        {
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
            sf.FormatFlags = StringFormatFlags.NoWrap;
            using (Font f = new Font("Tahoma", 9))
            {
                e.Graphics.DrawString(e.ToolTipText, f, 
                    SystemBrushes.ActiveCaptionText, e.Bounds, sf);
            }
        }
    }
    // Draw the ToolTip using default values if the ToolTip is for button3.
    else if (e.AssociatedControl == button3)
    {
        e.DrawBackground();
        e.DrawBorder();
        e.DrawText();
    }
}
' Handles drawing the ToolTip.
Private Sub toolTip1_Draw(ByVal sender As System.Object, _
    ByVal e As DrawToolTipEventArgs) Handles toolTip1.Draw
    ' Draw the ToolTip differently depending on which 
    ' control this ToolTip is for.

    ' Draw a custom 3D border if the ToolTip is for button1.
    If (e.AssociatedControl Is button1) Then
        ' Draw the standard background.
        e.DrawBackground()

        ' Draw the custom border to appear 3-dimensional.
        e.Graphics.DrawLines( _
            SystemPens.ControlLightLight, New Point() { _
            New Point(0, e.Bounds.Height - 1), _
            New Point(0, 0), _
            New Point(e.Bounds.Width - 1, 0)})
        e.Graphics.DrawLines( _
            SystemPens.ControlDarkDark, New Point() { _
            New Point(0, e.Bounds.Height - 1), _
            New Point(e.Bounds.Width - 1, e.Bounds.Height - 1), _
            New Point(e.Bounds.Width - 1, 0)})

        ' Specify custom text formatting flags.
        Dim sf As TextFormatFlags = TextFormatFlags.VerticalCenter Or _
                             TextFormatFlags.HorizontalCenter Or _
                             TextFormatFlags.NoFullWidthCharacterBreak

        ' Draw standard text with customized formatting options.
        e.DrawText(sf)
    ElseIf (e.AssociatedControl Is button2) Then
        ' Draw a custom background and text if the ToolTip is for button2.

        ' Draw the custom background.
        e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds)

        ' Draw the standard border.
        e.DrawBorder()

        ' Draw the custom text.
        Dim sf As StringFormat = New StringFormat
        Try
            sf.Alignment = StringAlignment.Center
            sf.LineAlignment = StringAlignment.Center
            sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None
            sf.FormatFlags = StringFormatFlags.NoWrap

            Dim f As Font = New Font("Tahoma", 9)
            Try
                e.Graphics.DrawString(e.ToolTipText, f, _
                    SystemBrushes.ActiveCaptionText, _
                    RectangleF.op_Implicit(e.Bounds), sf)
            Finally
                f.Dispose()
            End Try
        Finally
            sf.Dispose()
        End Try
    ElseIf (e.AssociatedControl Is button3) Then
        ' Draw the ToolTip using default values if the ToolTip is for button3.
        e.DrawBackground()
        e.DrawBorder()
        e.DrawText()
    End If
End Sub

설명

때문에 ToolTip 를 통해 여러 컨트롤을 사용 하 여 연결할 수 있습니다는 ToolTip.SetToolTip 메서드를를 AssociatedControl 속성 컨트롤을 확인할 수는 Draw 이벤트와 연결 합니다. 연결 된 컨트롤을 기반으로 하는 다양 한 도구 설명 사용자 지정을 수행 하려는 경우에 유용 합니다.

적용 대상

추가 정보