Making a WebBrowser!

Yep, I am making a web browser! in Visual C# using Microsoft Visual Studio. But I am not using the default “.NET” web browser component. I am using the CefSharp NuGet package. Here is a screenshot of the progress I have made!

screenShot1

I know I need to make it a more modern interface but first I have to get the functionality going. After that, I will make it look “pretty”. But till then I will keep trying to figure the functionality out. I was thinking of making this open source. But before I do that I have to finish it and then add comments in the code to give a basic rundown on what the code is doing. For example, here is a snippet of the code:

public void Form1_Load(object sender, System.EventArgs e)
{
CefSettings settings = new CefSettings();
//Initialize
Cef.Initialize(settings);
comboBox.Text = “https://www.google.com/”;
ChromiumWebBrowser chrome = new ChromiumWebBrowser(comboBox.Text);
chrome.Dock = DockStyle.Fill;
chrome.Parent = tabControl1.SelectedTab;
chrome.AddressChanged += Chrome_AddressChanged;
chrome.TitleChanged += Chrome_TitleChanged;
}

And if you’ve never programmed before you’re probably wondering what the heck all this means. But that is what I am about to do. And this will help explain how the comments in the code will be worded.

Okay, so first of all is the CefSettings settings = new CefSettings(); All this does is creates a new variable (I believe that’s the right term…) equal to the CefSettings method. After that, there is a comment that say’s “initialize” this will say that the next line(s) will initialize the variable from above. Then Cef.Initialize(settings); Will initialize the settings variable. As the comment said it would. After that you have comboBox.Text = "https://www.google.com/"; All this does is set the combo box’s text to google’s URL. Next up is the ChromiumWebBrowser chrome = new ChromiumWebBrowser(comboBox.Text); this creates another variable called chrome which I used to reference the browser control. And set’s it’s URL to the combo box’s text. After that, you have chrome.Dock = DockStyle.Fill; This just makes the web browser fill the parent object so it isn’t just set to one size. It will help a lot with resizing the window when you want to. After that, there is a line that says this: chrome.Parent = tabControl1.SelectedTab; This will make the web browser components parent object be the tab control‘s selected tab, it will help the chrome.Dock = DockStyle.Fill; when it fills it’s parent. We are almost done :D…

Next is chrome.AddressChanged += Chrome_AddressChanged; this will reference another function that will be activated when the web browsers web address is changed by the user. And Finally, chrome.TitleChanged += Chrome_TitleChanged; will reference the function that is in charge of the title if the document title is changed.

 

But anyways that is what I am working on if you would like to download an early version I made of it click this to see an older version. The version I linked doesn’t have tabs by the way. But that’s all I have to say except if you want to know anything else or even help with the project, just comment below or use the contact form on the contact page!

Have a great day!

Leave a comment