擴充IE WebControls之二:讓TreeView的每個節點顯示自己的ToolTip

來源:互聯網
上載者:User

作者:donna donna.zdn@gmail.com 自由轉載 但請保留作者資訊
   
    我在自己的網頁中用TreeView來做菜單導航,實際使用中經常遇到這種情況:由於需要顯示的內容比較長而頁面上又沒有充足的空間來顯示,導至使用者不能看到節點的全部內容。於是我想到了ToolTip屬性,當使用者用滑鼠指向某一節點時,在ToolTip裡顯示該項的使用內容。但TreeView控制項並沒有提供節點的ToolTip屬性,於是就有了這篇隨筆。
   
    1、為TreeView的節點添加ToolTip屬性
    開啟treenode.cs檔案添加如下內容:

    //add by donna;ToolTip
    /**//// <summary>
    /// ToolTip
    /// </summary>
    [DefaultValue("")]
    [Category("Appearance")]
    [ResDescription("ToolTip")]
    public string ToolTip
    {
        get
        {
            object obj = ViewState["ToolTip"];
            return (obj == null) ? String.Empty : (string)obj;
        }

        set { ViewState["ToolTip"] = value; }
    }
    //add end

    這樣就可以在設計時或在運行時使用代碼來修改節點的ToolTip了。
   
    2、在IE中顯示ToolTip
    首先,開啟treenode.cs檔案,在protected override void RenderUpLevelPath(HtmlTextWriter output)方法中添加如下內容:
 

   //add by donna; 用於在IE中顯示每個節點的ToolTip
    if (ToolTip != string.Empty)
        output.AddAttribute("title",ToolTip);
    //add end
    然後,開啟runtime目錄下的treeview.htc檔案,在function generateItem(el, nodeClass)方法中添加如下內容:
    //modified by donna ;用於在IE中顯示每個節點的ToolTip
    if (element.getAttribute("showToolTip") != false)
    {
     str = getNodeAttribute(el, "title");
     if (str != null && str != "")
     {
      if (nodeClass == "parent")
          accessAnchor.title = str + " : " + L_strToolTip_Text;
      else
       accessAnchor.title = str;
     }
    }
    //modify end

    
    3、在FireFox中顯示ToolTip
    開啟treenode.cs檔案,在protected override void RenderDownLevelPath(HtmlTextWriter output)方法中添加如下內容:

    //add by donna;在FireFox中顯示ToolTip
 if (ParentTreeView.ShowToolTip && ToolTip != string.Empty)
 {
  output.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
 }
 //add end

 
 使用方法:
 1、運行build.bat編譯控制項;
 2、將src\runtime\目錄下所有內容複寫到你的WEB應用程式目錄的webctrl_client\1_0\目錄下;
 3、請參考示範程式使用。

 環境:WIN2003、IIS6、VS2003、Framework1.1、IE6、FireFox1.5

代碼下載

請參考:擴充IE WebControls之一:讓Toolbar支援用戶端事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.