DrawToolTipEventArgs.Graphics プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

ToolTip を描画する Graphics。

Graphics オブジェクトを使用すると、ToolTip の特定のビジュアル部分の描画方法をカスタマイズできます。たとえば、Graphics.FillRectangle メソッドを使用すると、独自のツールヒントの背景を描画できます。
Bounds プロパティで指定された四角形の外側で行われるカスタム描画は、表示されません。ToolTip.Popup イベントを処理することで、ToolTip の表示前に、その境界を拡大できます。
DrawToolTipEventArgs クラスには、DrawBackground、DrawText、および DrawBorder の各メソッドも用意されており、ToolTip の各部分をオペレーティング システムが使用する標準的な方法で描画できます。これらのメソッドを Graphics オブジェクトのメソッドと共に使用すると、ツールヒントの一部を標準にする一方で、その他の部分をカスタマイズできます。

ToolTip をカスタム描画する方法を次のコード例に示します。この例では、ToolTip を作成し、Form 上にある 3 つの Button コントロールに関連付けています。また、OwnerDraw プロパティを true に設定し、Draw イベントを処理しています。Draw イベント ハンドラでは、どのボタンで ToolTip が表示されるかをDrawToolTipEventArgs.AssociatedControl プロパティで指定し、それによって ToolTip がカスタムで描画されます。
DrawText メソッドと DrawBackground メソッドの使用方法、および Graphics プロパティの使用方法を次のコード例の抜粋に示します。コード例全体については、DrawToolTipEventArgs クラスの概要を参照してください。
' 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)
// 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 == 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.get_AssociatedControl().Equals(button1)) { // Draw the standard background. e.DrawBackground(); // Draw the custom border to appear 3-dimensional. e.get_Graphics().DrawLines(SystemPens.get_ControlLightLight(), new Point[] { new Point(0, e.get_Bounds().get_Height() - 1), new Point(0, 0), new Point(e.get_Bounds().get_Width() - 1, 0)}); e.get_Graphics().DrawLines(SystemPens.get_ControlDarkDark(), new Point[] { new Point(0, e.get_Bounds().get_Height() - 1), new Point(e.get_Bounds().get_Width() - 1, e.get_Bounds().get_Height() - 1), new Point(e.get_Bounds().get_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); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDrawToolTipEventArgs.Graphics プロパティを検索する場合は、下記のリンクをクリックしてください。

- DrawToolTipEventArgs.Graphics プロパティのページへのリンク