DrawToolTipEventArgs.Graphics Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém a superfície gráfica usada para desenhar o 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
Valor de Propriedade
O Graphics sobre o qual desenhar o ToolTip.
Exemplos
O exemplo de código seguinte demonstra como desenhar manualmente o ToolTip. O exemplo cria um ToolTip e associa-o a três Button controlos localizados no Form. O exemplo define a OwnerDraw propriedade como verdadeira e trata do Draw evento. No Draw handler de eventos, o ToolTip é desenhado de forma personalizada de forma diferente dependendo do botão para o qual está ToolTip a ser exibido, conforme indicado pela DrawToolTipEventArgs.AssociatedControl propriedade.
O excerto do código abaixo demonstra o uso dos DrawText métodos and DrawBackground e a utilização da Graphics propriedade. Consulte a DrawToolTipEventArgs visão geral da classe para o exemplo completo do código.
// 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)
Observações
Usas o Graphics objeto para personalizar o desenho de certos aspetos visuais de um ToolTip. Por exemplo, pode desenhar o seu próprio fundo ToolTip usando o Graphics.FillRectangle método.
Qualquer desenho personalizado feito fora do retângulo especificado pela Bounds propriedade não vai aparecer. Pode aumentar os limites do ToolTip antes de ser mostrado ao lidar com o ToolTip.Popup evento.
A DrawToolTipEventArgs classe também fornece os DrawBackground, DrawText e DrawBorder métodos para desenhar partes individuais do ToolTip de forma padrão usada pelo sistema operativo. Pode usar estes métodos, juntamente com os Graphics métodos de objetos, para tornar algumas partes do seu ToolTip padrão, enquanto personaliza outras partes.