简体   繁体   中英

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. The code i am trying to use says: "Non-invocable member 'TabControl.TabPages' cannot be used like a method"

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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