Small white C # form Series-01. Easy Browser

Source: Internet
Author: User
Tags try catch

Recently seriously injured, today is just a holiday, to smoke out of the first episode of C #, the development is complete ... If you don't see this article, you can see it in a day.
Software download (. NET 4.0 framework) Http://pan.baidu.com/s/1c03X7vM "source see below"

First, design drawings:



Second, code Analysis
1. Back key, forward key, stop key, refresh key:
These functions originally I was prepared to use the number of groups to store, can forward and backward, and then chew his own method when he found that Microsoft provided a method, also stole a lazy
Back button This.webBrowser1.GoBack ();
Forward button This.webBrowser1.GoForward (); Stop button this.webBrowser1.Stop ();
Refresh button This.webBrowser1.Refresh ();

2. Jump function
Because it's often used, it all encapsulates 2 methods.
public void GetUrl () {URL = TxtUrl.Text.Trim ();//Remove space if (URL).            Length > 0)//input cannot be empty {reurl (URL); }        }

public void Reurl (string url) {try {
                // Remove the space and look at the beginning there is no http://or something                 if (URL. Trim (). StartsWith ("/http") | | Url. Trim (). StartsWith ("ftp://") | | Url. Trim (). StartsWith ("https://"))                 {                    Webbrowser1.url = new Uri (URL);//Web page start jump               &NBSP ;     Txturl.text = url;//The text of the address bar is also changed                }                else//It's not going to help you add                 {                    URL = "http +/" + url;            &N Bsp       Webbrowser1.url = new Uri (URL);                  &NBSP Txturl.text = url;               }           }&NBS P           catch            {          &NBS P     MessageBox.Show ("Pro, see if the address has a problem ~ ~", "Inverse Day friendly reminder");           }     & nbsp  } 3. Press ENTER to achieve jump function
This uses an event, which is a button-triggered event.
if (E.keycode = = Keys.enter) {GETURL ();//Custom Jump Method}

4. Computer mode browsing and mobile mode browsing
In fact, this is a train of thought, I do not know how other people do, I am the beginning of the WWW is the computer access to WAP is the beginning is mobile phone access
The code is also posted:
① Computer mode:
String url = TxtUrl.Text.Trim ().            Replace ("WAP.", "www."); Reurl (URL);//Custom Access method
② Phone Mode:
String url = TxtUrl.Text.Trim ().            Replace ("www.", "WAP."); Reurl (URL);
5. Eye-Protection Night mode
Originally I was prepared to use anti-color to get, such as setting the background for black, the font is white, and later found that WebBrowser not support, it was wretched a bit
Look at the code:
This.webBrowser1.Document.BackColor = Color.Black; This.webBrowser1.Document.ForeColor = Color.darkcyan; (1.1 will have a more powerful night mode)

6. Download the source code (the House icon in the upper right corner)
In fact, this is the use of thread startup to implement open your default browser access to my current article
Paste the code:
System.Diagnostics.Process.Start ("http://user.qzone.qq.com/1054186320/blog/1406614480");

7. Get cookies (this time without, simply call Microsoft's method)
Post code: (will be enhanced in 1.1)
Txturl.text = This.webBrowser1.Document.Cookie.ToString ();
You can add it yourself, the cookies are empty, the exception is handled, try Catch

8.?? Let the Web content open in the software (the most other thing in this project I have a sore egg)
When you jump to the site in a random point which hyperlink, he will open from IE, I think is not the default is the new form open? Later went to the online check, the code affixed:
Block open in IE, open in itself (WebBrowser NewWindow event)
E.cancel = true;//Block open in IE//will all the linked target, point to this form foreach (HtmlElement archor in This.webbrows Grs. Document.links) {Archor.            SetAttribute ("Target", "_self");                }//Will all the form's commit target, point to this form foreach (HtmlElement form in this.webBrowser1.Document.Forms) { Form.            SetAttribute ("Target", "_self"); }

9. For the time being, look at the source code, I write the source code is very detailed, patience to see is can understand

~ ~ ~ There is a flaw in the software, the 1.1 version will be perfect ~ ~ ~
1.??? Address bar Auto Fill (beautify)
2.??? Web page
3.?? More powerful cookies to get the function
4.?? Favorite Folders
5.?? Address bar Address Auto-transform
6.?? More Powerful night mode
7.??? Masking Section Script Tips
Wait a minute
Third, the source sharing http://pan.baidu.com/s/1bnGQOsn four, video sharing (next record, the body is too great)

"After the video is simple to take everyone to make a short version, and then explain my code ... 】
① main reasons: I have time for Tuesday and Saturday a week, and some other things to do;
② Plus this artwork what is too waste of time, such as this software, I have spent the art of 2h, playing code is only 2h;
③ said that at present, all my software and tutorials are free, there is no support and do not want to waste the time; in fact, everyone familiar with me knows that I have been opening a lot of small software during the school, each is free, But generally are 1.0,1.1, and so on, there are very few 2.0 versions, also on a counter-book is 2.0 version, not what, there is no one to support me, or I can not feel, so I open things enough for my own use is enough, also not happy to open the new version of ... (There is a need to tell me, I now help people open the software I do not charge ... )
④ Self-learning ability is really important, WebBrowser I also first contact, and then spend half a day to tinker, see vs comes with the method also almost mastered, mastered after you can make small things in fact nothing, refueling Pro ~ ~ ~

Recommended in this issue: C # Object-oriented (very good set of tutorials) Next: Build Your own QR code generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.