Hi, I need to make a browser in C# (I can use webbrowser I guess), and I need to create 2 buttons, one is on and one is off. If user selects on browser will load all the pictures in the page, if user selects off browser will load only the texts and will show an empty box instead of the images.
I need to do this with less possible coding.

It would be also very helpful if I can make the browser load the pictures in lower quality. (Anyway to load the images with lower quality!)

No there is no way to make the browser load the pictures in lower quality as the pictures are just transferred over the network as binary files that the browser then displays.

but if you write a tcp request and download the HTML of the page first and use regular expressions to remove the "IMG" html tags from the document then load that into the webbrowser control that will effectively show the text and not the pictures.

No there is no way to make the browser load the pictures in lower quality as the pictures are just transferred over the network as binary files that the browser then displays.

but if you write a tcp request and download the HTML of the page first and use regular expressions to remove the "IMG" html tags from the document then load that into the webbrowser control that will effectively show the text and not the pictures.

Thank you very much for your reply. Would you please explain more how I can do that(Loading the html without the images). Can I do this with C#? Is there anywhere I can find the codes?

I don't know of anywhere that would have done this already but I'm sorry as I don't know

here is a class that lets you get the Title from an html document

public class WebHelper 
    { 
        public static string FetchHTML(string sUrl) 
        { 
            System.Net.WebClient oClient = new System.Net.WebClient(); 
            return oClient.DownloadString(sUrl); 
            //return new System.Text.UTF8Encoding().GetString(oClient.DownloadData(sUrl)); 
        } 
 
        public static string FetchTitleFromHTML(string sHtml) 
        { 
            string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)"; 
            System.Text.RegularExpressions.Regex ex = new System.Text.RegularExpressions.Regex(regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
            return ex.Match(sHtml).Value.Trim(); 
 
        } 
 
    }

using the fetch HTML to get the text and then using the string.Replace method can get rid of the "<IMG SRC=" tags and just how the URL of the image in instead. just load that string into the WebBrowser control and you should be golden.

commented: Diamonddrake rocks! Thanks mate! +0
commented: great solution +1

I don't know of anywhere that would have done this already but I'm sorry as I don't know

here is a class that lets you get the Title from an html document

public class WebHelper 
    { 
        public static string FetchHTML(string sUrl) 
        { 
            System.Net.WebClient oClient = new System.Net.WebClient(); 
            return oClient.DownloadString(sUrl); 
            //return new System.Text.UTF8Encoding().GetString(oClient.DownloadData(sUrl)); 
        } 
 
        public static string FetchTitleFromHTML(string sHtml) 
        { 
            string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)"; 
            System.Text.RegularExpressions.Regex ex = new System.Text.RegularExpressions.Regex(regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
            return ex.Match(sHtml).Value.Trim(); 
 
        } 
 
    }

using the fetch HTML to get the text and then using the string.Replace method can get rid of the "<IMG SRC=" tags and just how the URL of the image in instead. just load that string into the WebBrowser control and you should be golden.

Thanks mate. This was amazing! It works great. Just I have a question, when using this code, are the images downloaded and not shown or they are not downloaded at all?

They are not downloaded at all, its just the text.

The browser first makes an tcp http request and asks for the text, That is what you have done with the get http method here. Then the browser parses the html and decides what it should look like and what else it needs to download from the server. Since you remove the IMG tags before you pass the html to the browser control the request for the images is never made.

They are not downloaded at all, its just the text.

The browser first makes an tcp http request and asks for the text, That is what you have done with the get http method here. Then the browser parses the html and decides what it should look like and what else it needs to download from the server. Since you remove the IMG tags before you pass the html to the browser control the request for the images is never made.

Brilliant. Thanks for your help. I had done many researches but this was the best way to solve the problem. Thank you very much.

They are not downloaded at all, its just the text.

The browser first makes an tcp http request and asks for the text, That is what you have done with the get http method here. Then the browser parses the html and decides what it should look like and what else it needs to download from the server. Since you remove the IMG tags before you pass the html to the browser control the request for the images is never made.

My last question: how can I set a button to activate this and deactivate it. Like a button (Show Images) and another button (Hide Images). I would highly appreciate your help on this as well. Thanks

Just use this method to download the html and save it to a variable, then parse out the IMG tags and save that to another variable. Then have a button that switches between them and loads the selected one into the webbrowser.

hello, I have a question that might be related to the one discussed.
I have a html text that I am getting from RSS feed. I contains text and images and some other tags. Since i do not want to connect to a certain page, I am setting the DocumentText of the control to the html text of the RSS feed. Everything appears correct by the images (embedded in the html) are not show. Is there is a way to show them?

use javascript and show hide images onclick of button

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.