Share via


DrawToolTipEventArgs.Graphics 屬性

定義

取得用來繪製 ToolTip 的圖形介面。

public:
 property System::Drawing::Graphics ^ Graphics { System::Drawing::Graphics ^ get(); };
public System.Drawing.Graphics Graphics { get; }
member this.Graphics : System.Drawing.Graphics
Public ReadOnly Property Graphics As Graphics

屬性值

要在其上繪製 GraphicsToolTip

範例

下列程式碼範例示範如何自訂繪製 ToolTip 。 此範例會建立 ,並將它與位於 上的 FormButtonToolTip 控制項產生關聯。 此範例會將 OwnerDraw 屬性設定為 true,並處理 Draw 事件。 在事件處理常式中 DrawToolTip 會根據 屬性所 DrawToolTipEventArgs.AssociatedControl 指示顯示的按鈕 ToolTip ,以不同的方式繪製 。

下列程式碼摘錄示範如何使用 DrawTextDrawBackground 方法和 屬性 GraphicsDrawToolTipEventArgs如需完整的程式碼範例,請參閱類別概觀。

// 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 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 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)

備註

Graphics您可以使用 物件來自訂 的特定視覺層面 ToolTip 繪圖。 例如,您可以使用 方法來繪製自己的工具提示背景 Graphics.FillRectangle

在 屬性所 Bounds 指定的矩形外部完成的任何自訂繪圖都不會顯示。 您可以藉由處理 ToolTip.Popup 事件,在顯示之前增加 的界限 ToolTip

類別 DrawToolTipEventArgs 也會提供 DrawBackgroundDrawTextDrawBorder 方法,以作業系統所使用的標準方式繪製 的個別部分 ToolTip 。 您可以使用這些方法與 Graphics 物件方法,來建立工具提示標準的某些部分,同時自訂其他元件。

適用於