简体   繁体   English

C#-TabControl图像索引问题

[英]C# - Issues with TabControl Image Index

So, i am making a web browser. 所以,我正在做一个网络浏览器。 It is a tabbed web browser and i want to be able to display favicons on the relevant tabs. 这是一个选项卡式Web浏览器,我希望能够在相关选项卡上显示收藏夹图标。 The code i am trying to use says: "Non-invocable member 'TabControl.TabPages' cannot be used like a method" 我试图使用的代码说: “不可调用的成员'TabControl.TabPages'不能像方法一样使用”

I know that i can't use it as a method but its the only way i can see adding the favicons. 我知道我不能将其用作方法,但是这是我看到添加图标的唯一方法。 Is there anyway to work around it while still being able to keep my code? 在仍然可以保留我的代码的情况下,是否有任何解决方法? Here is the code i am using: 这是我正在使用的代码:

 private void web_documentcompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser sender_wb = (WebBrowser)sender;
        int index_wb = Convert.ToInt32(sender_wb.Name.Replace("wb", ""));

        try
        {

            //Try to get website favicon using Google S2 Service.
            WebClient wc = new WebClient();
            System.IO.MemoryStream ms = new System.IO.MemoryStream(wc.DownloadData("http://www.google.com/s2/favicons?domain=" + sender_wb.Url.Host));
            Image img = Image.FromStream(ms);
            FaviconCollection.Images.Add(img);
            tabControl1.TabPages(index_wb).ImageIndex = FaviconCollection.Images.Count - 1;
            ms.Close();
        }
        catch (Exception ex)
        {

            //If failed, show WWW icon.
            tabControl1.TabPages(index_wb).ImageIndex = 0;
        }
    }

It's a collection not a method, you can access it like an array eg 这是一个集合而不是方法,您可以像访问数组一样访问它,例如

tabControl1.TabPages[index_wb].ImageIndex = FaviconCollection.Images.Count - 1;

You can also use things like .Add and .RemoveAt etc. the usual collection manipulation. 您还可以使用诸如.Add和.RemoveAt等之类的常用集合操作。

You'll want to put some bounds/null checking on there though to ensure you don't try to set a tab that doesn't exist. 您将希望在此处进行一些边界/空检查,以确保您不尝试设置不存在的选项卡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM