将工具提示分配给字符串 [英] assigning tool tip to a string

查看:64
本文介绍了将工具提示分配给字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时将所选项目的工具提示分配给字符串

解决方案

首先,将ToolTip控件添加到表单并将其命名为ttMain 。

然后只需调用SetToolTip方法,将字符串和想要显示的控件传递给它:

  string  tip =  string  .Format( 将文件\{0} \保存到磁盘,fileName); 
ttMain.SetToolTip(buttonSave,tip);


请检查下面aspx页面的代码: -

< pre lang =c#> <%@ 页面 语言 = < span class =code-keyword> C# AutoEventWireup = true CodeFile = Default4.aspx.cs 继承 = Default4 %>

< html xmlns = http:// www.w3.org/1999/xhtml\">
< head runat = server >
< title > < / title >
< / head >
< body >
< 表格 id = form1 runat = server >
< div >
< asp:image id = Image1 runat = server 工具提示 = 这是图像工具提示 / >
< / div >
< /表格 >
< / body >
< / html >



和背后的代码看起来像一个如下: -

 受保护 无效 Page_Load( object  sender,EventArgs e)
{
string str = Image1。工具提示;

Response.Write(str);
}





就像在运行时将任何文本分配给字符串一样直接。


how do i assign the tooltip of a selected item to a string during runtime

解决方案

First, add a ToolTip control to your form and call it "ttMain".
Then just call the SetToolTip method, passing it the string and the control you want to display it for:

string tip = string.Format("Save the file \"{0}\" to disk", fileName);
ttMain.SetToolTip(buttonSave, tip);


please check the code for aspx page below :-

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:image id="Image1" runat="server" tooltip="This is image tooltip"   />
    </div>
    </form>
</body>
</html>


and the code behind page look like as below :-

protected void Page_Load(object sender, EventArgs e)
    {
        string str = Image1.ToolTip;

        Response.Write(str);
    }



It as straight as assigning any text to string at runtime.


这篇关于将工具提示分配给字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆