DrawToolTipEventArgs 클래스

정의

Draw 이벤트에 대한 데이터를 제공합니다.

public ref class DrawToolTipEventArgs : EventArgs
public class DrawToolTipEventArgs : EventArgs
type DrawToolTipEventArgs = class
    inherit EventArgs
Public Class DrawToolTipEventArgs
Inherits EventArgs
상속
DrawToolTipEventArgs

예제

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

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::VisualStyles;

// Form for the ToolTip example.
public ref class ToolTipExampleForm: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::ToolTip^ toolTip1;
   System::Windows::Forms::Button^ button1;
   System::Windows::Forms::Button^ button2;
   System::Windows::Forms::Button^ button3;

public:
   ToolTipExampleForm()
   {
      // Create the ToolTip and set initial values.
      this->toolTip1 = gcnew System::Windows::Forms::ToolTip;
      this->toolTip1->AutoPopDelay = 5000;
      this->toolTip1->InitialDelay = 500;
      this->toolTip1->OwnerDraw = true;
      this->toolTip1->ReshowDelay = 10;
      this->toolTip1->Draw += gcnew DrawToolTipEventHandler( this, &ToolTipExampleForm::toolTip1_Draw );
      
      // Create button1 and set initial values.
      this->button1 = gcnew System::Windows::Forms::Button;
      this->button1->Location = System::Drawing::Point( 8, 8 );
      this->button1->Text = "Button 1";
      this->toolTip1->SetToolTip( this->button1, "Button1 tip text" );
      
      // Create button2 and set initial values.
      this->button2 = gcnew System::Windows::Forms::Button;
      this->button2->Location = System::Drawing::Point( 8, 32 );
      this->button2->Text = "Button 2";
      this->toolTip1->SetToolTip( this->button2, "Button2 tip text" );
      
      // Create button3 and set initial values.
      this->button3 = gcnew System::Windows::Forms::Button;
      this->button3->Location = System::Drawing::Point( 8, 56 );
      this->button3->Text = "Button 3";
      this->toolTip1->SetToolTip( this->button3, "Button3 tip text" );
      
      // Set up the Form.
      array<Control^>^temp0 = {this->button1,this->button2,this->button3};
      this->Controls->AddRange( temp0 );
      this->Text = "owner drawn ToolTip example";
   }

protected:

   ~ToolTipExampleForm()
   {
      if ( toolTip1 != nullptr )
      {
         delete toolTip1;
      }
   }

   // 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();
      }
   }
};

// The main entry point for the application.

[STAThread]
int main()
{
   Application::Run( gcnew ToolTipExampleForm );
}
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ToolTipExample
{
    // Form for the ToolTip example.
    public class ToolTipExampleForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;

        public ToolTipExampleForm()
        {
            // Create the ToolTip and set initial values.
            this.toolTip1 = new System.Windows.Forms.ToolTip();
            this.toolTip1.AutoPopDelay = 5000;
            this.toolTip1.InitialDelay = 500;
            this.toolTip1.OwnerDraw = true;
            this.toolTip1.ReshowDelay = 10;
            this.toolTip1.Draw += new DrawToolTipEventHandler(this.toolTip1_Draw);
            this.toolTip1.Popup += new PopupEventHandler(toolTip1_Popup);

            // Create button1 and set initial values.
            this.button1 = new System.Windows.Forms.Button();
            this.button1.Location = new System.Drawing.Point(8, 8);
            this.button1.Text = "Button 1";
            this.toolTip1.SetToolTip(this.button1, "Button1 tip text");

            // Create button2 and set initial values.
            this.button2 = new System.Windows.Forms.Button();
            this.button2.Location = new System.Drawing.Point(8, 32);
            this.button2.Text = "Button 2";
            this.toolTip1.SetToolTip(this.button2, "Button2 tip text");

            // Create button3 and set initial values.
            this.button3 = new System.Windows.Forms.Button();
            this.button3.Location = new System.Drawing.Point(8, 56);
            this.button3.Text = "Button 3";
            this.toolTip1.SetToolTip(this.button3, "Button3 tip text");

            // Set up the Form.
            this.Controls.AddRange(new Control[] {
                this.button1, this.button2, this.button3
            });
            this.Text = "owner drawn ToolTip example";
        }

        // Clean up any resources being used.        
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                toolTip1.Dispose();
            }

            base.Dispose(disposing);
        }

        // The main entry point for the application.
        [STAThread]
        static void Main()
        {
            Application.Run(new ToolTipExampleForm());
        }

        // Determines the correct size for the button2 ToolTip.
        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {
            if (e.AssociatedControl == button2)
            {
                using (Font f = new Font("Tahoma", 9))
                {
                    e.ToolTipSize = TextRenderer.MeasureText(
                        toolTip1.GetToolTip(e.AssociatedControl), f);
                }
            }
        }

        // 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();
            }
        }
    }
}
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.VisualStyles

Public Module ToolTipExampleApp
    ' The main entry point for the application.
    <STAThread()> _
    Sub Main()
        Application.Run(New ToolTipExampleForm)
    End Sub
End Module

' Form for the ToolTip example.
Public Class ToolTipExampleForm
    Inherits System.Windows.Forms.Form

    Private WithEvents toolTip1 As System.Windows.Forms.ToolTip
    Private WithEvents button1 As System.Windows.Forms.Button
    Private WithEvents button2 As System.Windows.Forms.Button
    Private WithEvents button3 As System.Windows.Forms.Button

    Public Sub New()
        ' Create the ToolTip and set initial values.
        Me.toolTip1 = New System.Windows.Forms.ToolTip
        Me.toolTip1.AutoPopDelay = 5000
        Me.toolTip1.InitialDelay = 500
        Me.toolTip1.OwnerDraw = True
        Me.toolTip1.ReshowDelay = 10

        ' Create button1 and set initial values.
        Me.button1 = New System.Windows.Forms.Button
        Me.button1.Location = New System.Drawing.Point(8, 8)
        Me.button1.Text = "Button 1"
        Me.toolTip1.SetToolTip(Me.button1, "Button1 tip text")

        ' Create button2 and set initial values.
        Me.button2 = New System.Windows.Forms.Button
        Me.button2.Location = New System.Drawing.Point(8, 32)
        Me.button2.Text = "Button 2"
        Me.toolTip1.SetToolTip(Me.button2, "Button2 tip text")

        ' Create button3 and set initial values.
        Me.button3 = New System.Windows.Forms.Button
        Me.button3.Location = New System.Drawing.Point(8, 56)
        Me.button3.Text = "Button 3"
        Me.toolTip1.SetToolTip(Me.button3, "Button3 tip text")

        ' Set up the Form.
        Me.Controls.AddRange(New Control() {Me.button1, _
                                            Me.button2, _
                                            Me.button3})
        Me.Text = "owner drawn ToolTip example"
    End Sub

    ' Clean up any resources being used.        
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If (disposing) Then
            toolTip1.Dispose()
        End If

        MyBase.Dispose(disposing)
    End Sub

    ' Determines the correct size for the button2 ToolTip.
    Private Sub toolTip1_Popup(ByVal sender As System.Object, _
        ByVal e As PopupEventArgs) Handles toolTip1.Popup

        If e.AssociatedControl Is button2 Then

            Dim f As New Font("Tahoma", 9)
            Try
                e.ToolTipSize = TextRenderer.MeasureText( _
                    toolTip1.GetToolTip(e.AssociatedControl), f)
            Finally
                f.Dispose()
            End Try

        End If
    End Sub

    ' 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
End Class

설명

ToolTip.Draw 이벤트를 발생 합니다 ToolTip 때 클래스는 ToolTip 그려집니다 및 ToolTip.OwnerDraw 속성 값이 true합니다. 이 이벤트 처리기 형식의 매개 변수를 받는 DrawToolTipEventArgs합니다. DrawToolTipEventArgs 그리는 데 필요한 모든 정보를 포함 하는 클래스를 ToolTip등의 ToolTip 텍스트를 Rectangle, 및 Graphics 드로잉을 수행할 수 해야 하는 개체가. 도구 설명의 모양을 사용자 지정을 사용 하 여는 Rectangle 도구 설명의 범위를 확인 하 고 Graphics 에 사용자 지정된 그리기를 수행 하는 개체입니다. 범위를 확장할 수는 ToolTip 처리 하 여 표시 되기 전에 Popup 이벤트입니다.

DrawToolTipEventArgs 또한 통해 부분 사용자 지정을 지원 합니다 DrawBackground, DrawTextDrawBorder 메서드. 이러한 메서드를 사용 하면 도구 설명의 일부를 소유자 그리기 표준 방식으로 그린 나머지 부분은 그대로 유지 하면서.

생성자

DrawToolTipEventArgs(Graphics, IWin32Window, Control, Rectangle, String, Color, Color, Font)

DrawToolTipEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

AssociatedControl

ToolTip을 그릴 대상 컨트롤을 가져옵니다.

AssociatedWindow

ToolTip이 바인딩된 창을 가져옵니다.

Bounds

그릴 ToolTip의 크기와 위치를 가져옵니다.

Font

ToolTip을 그리는 데 사용되는 글꼴을 가져옵니다.

Graphics

ToolTip을 그리는 데 사용되는 그래픽 표면을 가져옵니다.

ToolTipText

그리고 있는 ToolTip의 텍스트를 가져옵니다.

메서드

DrawBackground()

시스템 배경색을 사용하여 ToolTip의 배경을 그립니다.

DrawBorder()

시스템 테두리 색을 사용하여 ToolTip의 테두리를 그립니다.

DrawText()

시스템 텍스트 색과 글꼴을 사용하여 ToolTip의 텍스트를 그립니다.

DrawText(TextFormatFlags)

시스템 텍스트 색과 글꼴 및 지정된 텍스트 레이아웃을 사용하여 ToolTip의 텍스트를 그립니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보