WebControl.ToolTip プロパティ

定義

マウス ポインターが Web サーバー コントロールの上を移動したときに表示されるテキストを取得または設定します。

public:
 virtual property System::String ^ ToolTip { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string ToolTip { get; set; }
public virtual string ToolTip { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ToolTip : string with get, set
member this.ToolTip : string with get, set
Public Overridable Property ToolTip As String

プロパティ値

マウス ポインターが Web サーバー コントロールの上を移動したときに表示されるテキスト。 既定値は、Empty です。

属性

次の例は、基本クラスから継承される コントロールに プロパティをButton設定ToolTipする方法をWebControl示しています。

Note

次のコード サンプルでは、単一ファイルコード モデルを使用しており、分離コード ファイルに直接コピーすると正しく動作しない場合があります。 このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。 Web Forms コード モデルの詳細については、「ASP.NET Web Forms ページ コード モデル」を参照してください。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
 
    void SubmitBtn_Click(object sender, EventArgs e)
    {
        if (((Button)sender).CommandArgument == "1")
            Label1.Text = "Share your happiness!";
        else
            Label1.Text = "Be happy!";

        Label1.BorderColor = System.Drawing.Color.BurlyWood;
        Label1.BorderWidth = 4;
    }
 
 </script>
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
    <title>WebControl.ToolTip Example</title>
 </head>
 <body>
 <form id="Form1" runat="server">
 
    <h3>ToolTip Property of a Web Control</h3>
    <p>Don't know which button to click?<br />
        Move the mouse pointer over the buttons to find out!
    </p>

    <p><asp:Button id="SubmitBtn1" OnClick="SubmitBtn_Click" 
            Text="Click Me" CommandArgument="1"
            ToolTip="Click me if you are happy" runat="server"/>
    </p>

    <p><asp:Button id="SubmitBtn2" OnClick="SubmitBtn_Click" 
            Text="Click Me" CommandArgument="2"
            ToolTip="Click me if you are sad." runat="server"/>
    </p>

    <asp:Label id="Label1" Font-size="24pt" Font-Bold="True" 
        BackColor="Yellow" runat="server"/>

 </form>
 
 </body>
 </html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <script language="VB" runat="server">
 
    Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
        If CType(sender, Button).CommandArgument = "1" Then
            Label1.Text = "Share your happiness!"
        Else
            Label1.Text = "Be happy!"
        End If
        Label1.BorderColor = Drawing.Color.BurlyWood
        Label1.BorderWidth = 4
    End Sub
 
 </script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>ToolTip Property of a Web Control</title>
</head>
<body>
  
 <form id="form1" runat="server">
 
    <h3>ToolTip Property of a Web Control</h3>
    <p>Don't know which button to click?<br />
        Move the mouse pointer over the buttons to find out!
    </p>

    <p><asp:Button id="SubmitBtn1" OnClick="SubmitBtn_Click" 
            Text="Click Me" CommandArgument="1"
            ToolTip="Click me if you are happy" runat="server"/>
    </p>

    <p><asp:Button id="SubmitBtn2" OnClick="SubmitBtn_Click" 
            Text="Click Me" CommandArgument="2"
            ToolTip="Click me if you are sad." runat="server"/>
    </p>

    <asp:Label id="Label1" Font-size="24pt" Font-Bold="True" 
        BackColor="Yellow" runat="server"/>

 </form>
 
 </body>
 </html>

注釈

プロパティを ToolTip 使用して、マウス ポインターが Web サーバー コントロールの上に置いたときに表示されるカスタム テキストを指定します。

Note

このプロパティは、すべてのブラウザーに対してレンダリングされます。 ただし、Microsoft インターネット エクスプローラーのみがこのプロパティをツールヒントとして表示します。 他のすべてのブラウザーでは、このプロパティは無視されます。

このプロパティの値を設定すると、デザイナー ツールを使用してリソース ファイルに自動的に保存できます。 詳細については、グローバリゼーションとローカライズに関するページを参照してくださいLocalizableAttribute

適用対象

こちらもご覧ください