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

Draw イベントが発生したときに ToolTip に関連付けられているテキスト。

通常、ToolTipText プロパティは、ツールヒントをカスタム描画するときに、ツールヒント テキストの内容を確認するために使用します。Graphics.DrawString メソッドを使用すると、ツールヒント テキストの描画方法をカスタマイズできます。システムで指定されたスタイルでツールヒント テキストを描画する場合は、DrawText メソッドを使用します。テキストの値は、ToolTip クラスの SetToolTip メソッドに渡された値から取得されます。

ToolTip をカスタム描画する方法を次のコード例に示します。この例では、ToolTip を作成し、Form 上にある 3 つの Button コントロールに関連付けています。また、OwnerDraw プロパティを true に設定し、Draw イベントを処理しています。Draw イベント ハンドラでは、どのボタンで ToolTip が表示されるかをDrawToolTipEventArgs.AssociatedControl プロパティで指定し、それによって ToolTip がカスタムで描画されます。
DrawBorder メソッドの使用方法、および Bounds、ToolTipText、および Graphics の各プロパティの使用方法を次のコード例の抜粋に示します。コード例全体については、DrawToolTipEventArgs クラスの概要を参照してください。
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
// 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 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 a custom background and text if the ToolTip is for button2. else { if (e.get_AssociatedControl().Equals(button2)) { // Draw the custom background. e.get_Graphics().FillRectangle(SystemBrushes.get_ActiveCaption(), e.get_Bounds()); // Draw the standard border. e.DrawBorder(); // Draw the custom text. // The using block will dispose the StringFormat automatically. StringFormat sf = new StringFormat(); try { sf.set_Alignment(StringAlignment.Center); sf.set_LineAlignment(StringAlignment.Center); sf.set_HotkeyPrefix(System.Drawing.Text.HotkeyPrefix.None); sf.set_FormatFlags(StringFormatFlags.NoWrap); Font f = new Font("Tahoma", 9); try { e.get_Graphics().DrawString(e.get_ToolTipText(), f, SystemBrushes.get_ActiveCaptionText(), RectangleF.op_Implicit(e.get_Bounds()), sf); } finally { f.Dispose(); } } finally { sf.Dispose(); } }

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.ToolTipText プロパティを検索する場合は、下記のリンクをクリックしてください。

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