954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to create a webbrowser that doesn't load the pictures C#

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!)

user20000
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

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?

user20000
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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 "html>

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

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 "html>

user20000
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

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.

user20000
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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

user20000
Newbie Poster
5 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

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.

Diamonddrake
Master Poster
724 posts since Mar 2008
Reputation Points: 442
Solved Threads: 89
 

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?

checho
Light Poster
34 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

use javascript and show hide images onclick of button

crishlay
Junior Poster
132 posts since May 2010
Reputation Points: 10
Solved Threads: 16
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: