Wednesday, 21 February 2018

C# - Microsoft Tutorial: missing code for webBrowser in winforms

So a very good StackOverflow question asks about using HTML as the GUI technology for a WinForms desktop application. I can sympathise with this because the Excel worksheet is already a rich GUI and so for forms do I really need to keep current with WinForms and WPF etc. can't I write forms in HTML please?

So just working this tutorial from Microsoft but sadly there are a few lines missing from the Form1.Designer.cs class where all the controls are defined to be members of the Form1 class.

Here is the missing code which you should place at bottom of Form1.Designer.cs


        private void InitializeComponent()
        {
            // ... Designer authored code goes here do not modify...  
        }

        #endregion

        // Here the new code begins
        private System.Windows.Forms.WebBrowser webBrowser1;
        private System.Windows.Forms.MenuStrip menuStrip1; 

        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem;

        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;

        private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem printPreviewToolStripMenuItem;

        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;

        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem pageSetupToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem propertiesToolStripMenuItem;

        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.ToolStripButton goButton;
        private System.Windows.Forms.ToolStripButton backButton;
        private System.Windows.Forms.ToolStripButton forwardButton;
        private System.Windows.Forms.ToolStripButton stopButton;
        private System.Windows.Forms.ToolStripButton refreshButton;
        private System.Windows.Forms.ToolStripButton homeButton; 
        private System.Windows.Forms.ToolStripButton searchButton; 
        private System.Windows.Forms.ToolStripButton printButton;

        private System.Windows.Forms.ToolStrip toolStrip2; 
        private System.Windows.Forms.ToolStripTextBox toolStripTextBox1; 

        private System.Windows.Forms.StatusStrip statusStrip1;  
        private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; 
        // Here the new code ends
    }
}


Early experiments show this browser control doesn't like JSON parsing as found in JQuery. I wonder how much Javascript is compromised. I also wonder if in fact one could write a pure HTML web page and handle events in C#.

No comments:

Post a Comment