Esempio n. 1
0
        public MainForm()
        {
            InitializeComponent();

            this.wb      = new WebBrowser();
            this.wb.Dock = DockStyle.Fill;
            this.Controls.Add(this.wb);
            this.wb.Visible = true;

            var dynamicComponent = new DynamicComponent();

            // make dynamicComponent available to VBScript
            this.wb.ObjectForScripting = dynamicComponent;

            // add a dynamic method "Convert"
            dynamicComponent.SetMethod("Convert", new Func <int, string>((a) =>
            {
                MessageBox.Show("Convert called: " + a.ToString());
                return(a.ToString());
            }));

            this.Load += (s, e) =>
            {
                this.wb.DocumentText =
                    "<script type='text/vbscript'>\n" +
                    "Sub OnLoadHandler\n" +
                    "    alert window.external.Convert(42)\n" +
                    "End Sub\n" +
                    "window.onload = GetRef(\"OnLoadHandler\")\n" +
                    "</script>";
            };
        }
        public MainForm()
        {
            InitializeComponent();

            this.wb      = new WebBrowser();
            this.wb.Dock = DockStyle.Fill;
            this.Controls.Add(this.wb);
            this.wb.Visible = true;

            var dynamicComponent = new DynamicComponent();

            // make dynamicComponent available to VBScript
            this.wb.ObjectForScripting = dynamicComponent;

            // add a dynamic mathod
            dynamicComponent.SetMethod("Convert", new Func <int, string>((a) =>
            {
                MessageBox.Show("Convert called: " + a.ToString());
                return(a.ToString());
            }));

            this.Load += (s, e) =>
            {
                this.wb.Navigate("http://localhost:81/vbtest.html");
            };
        }