Detailed introduction to several methods of C# calling the default browser to open a web page (picture)

黄舟
Release: 2017-03-13 17:49:53
Original
3068 people have browsed it

Several ways for CSharp to call the default browser to open a web page

Sample interface:


Method 1: Read from the registry Default browser executable file path

        private void button1_Click(object sender, EventArgs e)
        {
            //从注册表中读取默认浏览器可执行文件路径
            RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
            string s = key.GetValue("").ToString();

            //s就是你的默认浏览器,不过后面带了参数,把它截去,不过需要注意的是:不同的浏览器后面的参数不一样!
            //"D:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -- "%1"
            System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), "http://blog.csdn.net/testcs_dn");
        }
Copy after login

Method 2:

        private void button2_Click(object sender, EventArgs e)
        {
            //调用系统默认的浏览器 
            System.Diagnostics.Process.Start("explorer.exe", "http://blog.csdn.net/testcs_dn");
        }
Copy after login

Method 3:

        private void button3_Click(object sender, EventArgs e)
        {
            //调用系统默认的浏览器 
            System.Diagnostics.Process.Start("http://blog.csdn.net/testcs_dn");
        }
Copy after login

Method 4: Call IE browser

        private void button4_Click(object sender, EventArgs e)
        {
            //调用IE浏览器  
            System.Diagnostics.Process.Start("iexplore.exe", "http://blog.csdn.net/testcs_dn");
        }
Copy after login

Principle Generally speaking, method two and method three should be the same, but the code of method three is shorter.

The above is the detailed content of Detailed introduction to several methods of C# calling the default browser to open a web page (picture). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template