How to web browser in C#

The Web Browser control in C# provides a convenient way to host and display web pages and other web browser-enabled documents within your Windows Forms applications. By adding the browser control to your C# projects, you can offer a user interface that resembles commercial web browsers, allowing users to interact with and view web content seamlessly.

Web Browser control

The Web Browser control offers a wide range of possibilities, including integrating HTML-based user assistance or incorporating web browsing capabilities directly into your application. It provides a familiar browsing experience, enabling users to navigate websites, interact with web forms, and access web-based resources.

web-browser

The Web Browser control exposes various properties, methods, and events that are associated with navigation. These features allow you to control and customize the behavior of the browser control within your application. You can programmatically navigate to specific URLs, handle navigation events such as page loading and completion, manipulate the browser's history, and interact with the DOM (Document Object Model) of the displayed web page. The following C# program displays a web page in browser window and also you can retrieve the source code of the same web page with another button click.

Full Source C#
using System; using System.IO; using System.Net; using System.Diagnostics; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click_1(object sender, EventArgs e) { webBrowser1.Navigate(textBox1.Text ); } private void button2_Click(object sender, EventArgs e) { String source = ("viewsource.txt"); StreamWriter writer = File.CreateText(source); writer.Write(webBrowser1.DocumentText); writer.Close(); Process.Start("notepad.exe", source); } } }

Conclusion

Using the Web Browser control, you can enhance the functionality of your C# applications by seamlessly integrating web content and providing users with a rich browsing experience. Whether you need to display web-based documentation, implement web-based features, or create hybrid desktop-web applications, the Web Browser control offers a powerful solution for incorporating web browsing capabilities directly into your C# projects.