WebControl.ToolTip WebControl.ToolTip WebControl.ToolTip WebControl.ToolTip Property

定義

取得或設定當滑鼠指標停留在 Web 伺服器控制項時顯示的文字。Gets or sets the text displayed when the mouse pointer hovers over the Web server control.

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

屬性值

當滑鼠停留在 Web 伺服器控制項時顯示的文字。The text displayed when the mouse pointer hovers over the Web server control. 預設為 EmptyThe default is Empty.

範例

下列範例說明如何設定ToolTip Button控制項(繼承自WebControl基類)上的屬性(property)。The following example illustrates how to set the ToolTip property on the Button control, which is inherited from the WebControl base class.

注意

下列程式碼範例會使用單一檔案程式碼模型,如果直接複製到程式碼後置檔案中,則可能無法正確運作。The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. 此程式碼範例必須複製到具有 .aspx 副檔名的空白文字檔。This code sample must be copied into an empty text file that has an .aspx extension. 如需 Web Forms 程式碼模型的詳細資訊,請參閱ASP.NET Web Form 頁面程式碼模型For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.

<%@ 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 服務器控制項上時所顯示的自訂文字。Use the ToolTip property to specify the custom text that is displayed when the mouse pointer hovers over the Web server control.

注意

所有瀏覽器都會呈現這個屬性。This property is rendered for all browsers. 不過,只有 Microsoft Internet Explorer 會將此屬性顯示為工具提示。However, only Microsoft Internet Explorer will display this property as a ToolTip. 所有其他瀏覽器都會忽略此屬性。All other browsers will ignore this property.

設定這個屬性的值時,可以使用設計工具,自動儲存到資源檔中。The value of this property, when set, can be saved automatically to a resource file by using a designer tool. 如需詳細資訊, LocalizableAttribute請參閱和全球化和當地語系化For more information, see LocalizableAttribute and Globalization and Localization.

適用於

另請參閱