0

I have studied the several questions relating to this topic(Cannot force WebBrowser Control to render using current version of IE ,Use latest version of Internet Explorer in the webbrowser control) but my C# knowledge is too basic to find out where I should be placing this 'fix' in my code.

I am using visual studio 2015 and writing a winforms application in C#. The application consists of a web browser that displays local HTML files, some of which are using jquery and javascript. I know I have to edit the registry but I have no clue on how to go about this safely. The code provided in the second link seems good, but I don't know what to change in it so it applies to my project and where to place it in my code.

my Form1.cs so far.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Web_Browser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


        }



        private void button4_Click(object sender, EventArgs e)
        {
            string curDir = Directory.GetCurrentDirectory();
            this.webBrowser1.Url = new Uri(String.Format("file:///{0}/post-op/index.html", curDir));
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }


        private void navigateToPage()
        {
            var filemapping = new Dictionary<string, string>
        {
            { "www.xy.com", "file:///{0}/XY/index.html" },
            { "www.post-op.com", "file:///{0}/post-op/index.html" },
            { "www.free-mail.com", "file:///{0}/mail/index.html"},
            { "test", "file:///{0}/index.html" },

        };

            var textEntered = textBox1.Text;

            string filename;
            if (filemapping.TryGetValue(textEntered, out filename))
            {
                string curDir = Directory.GetCurrentDirectory();
                var uri = new Uri(String.Format(filename, curDir));
                webBrowser1.Navigate(uri);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

            navigateToPage();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)ConsoleKey.Enter)
            {
                navigateToPage();
            }
        }

        private void backButton_Click(object sender, EventArgs e)
        {
            webBrowser1.GoBack();
        }

        private void forwardButton_Click(object sender, EventArgs e)
        {
            webBrowser1.GoForward();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string curDir = Directory.GetCurrentDirectory();
            this.webBrowser1.Url = new Uri(String.Format("file:///{0}/mail/index.html", curDir));
        }


    }
}

Sorry if this seems stupid. I have really tried to solve this issue on my own with the answers already given on the several questions on SO, but i'm a bit lost atm.

Community
  • 1
  • 1
gezer4000
  • 103
  • 8

0 Answers0