Ejemplo n.º 1
0
        private void AboutDemo()
        {
            Form aboutDemo = new Form();

            aboutDemo.ShowIcon        = false;
            aboutDemo.Size            = new Size(380, 300);
            aboutDemo.Text            = "About Demo";
            aboutDemo.FormBorderStyle = FormBorderStyle.FixedDialog;
            aboutDemo.MaximizeBox     = false;
            aboutDemo.MinimizeBox     = false;
            aboutDemo.StartPosition   = FormStartPosition.CenterParent;

            String      strVersion  = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            BrowserView browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.HEAVYWEIGHT));

            aboutDemo.Controls.Add((Control)browserView);

            string textAboutDemo = "<br>" + "<html><font face='Arial' size='2'>" +
                                   "<font size='5'>DotNetBrowser Demo</font><br><br>" +
                                   "<b>Version " + strVersion + "</b><br><br>" +
                                   "<base target='_blank'>" +

                                   "This application is created for demonstration purposes only.<br>" +
                                   "&copy; 2017 TeamDev Ltd. All rights reserved.<br><br>" +

                                   "Powered by <a color='#3d82f8' href='https://www.teamdev.com/dotnetbrowser' " +
                                   "style='text-decoration:none'>DotNetBrowser</a>. See " +
                                   "<a color='#3d82f8' href='https://www.teamdev.com/dotnetbrowser-licence-agreement' " +
                                   "style='text-decoration:none'>terms of use.</a><br>" +

                                   "Based on <a color='#3d82f8' href='http://www.chromium.org/' " +
                                   "style='text-decoration:none'>Chromium project</a>. " +
                                   "See <a color='#3d82f8' " +
                                   "href='http://dotnetbrowser-support.teamdev.com/documentation/open-source-components-licences' " +
                                   "style='text-decoration:none'>full list</a> of Chromium<br>components, " +
                                   "used in the current DotNetBrowser version.<br><br>" +

                                   "This demo uses WebKit project under LGPL.<br>" +

                                   "See licence text " +
                                   "<a color='#3d82f8' href='https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html' " +
                                   "style='text-decoration:none'>LGPL v.2</a> and " +
                                   "<a color='#3d82f8' href='https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html' " +
                                   "style='text-decoration:none'>LGPL v.2.1</a></font></html>";

            browserView.Browser.LoadHTML(textAboutDemo);

            aboutDemo.FormClosing += delegate
            {
                if (!browserView.Browser.IsDisposed())
                {
                    browserView.Browser.Dispose();
                    browserView.Dispose();
                }
            };

            aboutDemo.ShowDialog();
        }
Ejemplo n.º 2
0
        //public string GetUiState()
        //{
        //    JSObject document = (JSObject)browser.ExecuteJavaScriptAndReturnValue("document.stairDesigner");
        //    return document.ToJSONString();
        //}

        public bool CloseWindow()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new Action(() =>
                {
                    this.Close();
                }));
            }
            else
            {
                this.Close();
                BrowserView.Dispose();
            }

            return true;
        }
Ejemplo n.º 3
0
 public void DisposeForm()
 {
     browserView.Dispose();
     browserView.Browser.Dispose();
 }
        private void toolStripUpload_Click(object sender, EventArgs e)
        {
            //Create new browser for rendering
            WinFormsBrowserView browserView1 = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT));
            Browser             browser      = browserView1.Browser;

            // #1 Set browser initial size
            browserView1.Browser.SetSize(1280, 1024);

            // #2 Load web page and wait until web page is loaded completely.
            ManualResetEvent          resetEvent = new ManualResetEvent(false);
            FinishLoadingFrameHandler listener   = new FinishLoadingFrameHandler((object sender1, FinishLoadingEventArgs e1) =>
            {
                if (e1.IsMainFrame)
                {
                    resetEvent.Set();
                }
            });

            browser.FinishLoadingFrameEvent += listener;
            try
            {
                browser.LoadURL(toolStripAddress.Text.ToString());
                resetEvent.WaitOne(new TimeSpan(0, 0, 45));
            }
            finally
            {
                browser.FinishLoadingFrameEvent -= listener;
            }

            // #3 Set the required document size.
            JSValue documentHeight = browserView1.Browser.ExecuteJavaScriptAndReturnValue(
                "Math.max(document.body.scrollHeight, " +
                "document.documentElement.scrollHeight, document.body.offsetHeight, " +
                "document.documentElement.offsetHeight, document.body.clientHeight, " +
                "document.documentElement.clientHeight);");
            JSValue documentWidth = browserView1.Browser.ExecuteJavaScriptAndReturnValue(
                "Math.max(document.body.scrollWidth, " +
                "document.documentElement.scrollWidth, document.body.offsetWidth, " +
                "document.documentElement.offsetWidth, document.body.clientWidth, " +
                "document.documentElement.clientWidth);");

            int scrollBarSize = 25;

            int viewWidth  = (int)documentWidth.GetNumber() + scrollBarSize;
            int viewHeight = (int)documentHeight.GetNumber() + scrollBarSize;

            // #4 Register OnRepaint to get notifications
            // about paint events. We expect that web page will be completely rendered twice:
            // 1. When its size is updated.
            // 2. When HTML content is loaded and displayed.
            //ManualResetEvent waitEvent = new ManualResetEvent(false);

            DrawingView drawingView = (DrawingView)browserView1.GetImage();

            browserView1.Browser.SetSize(viewWidth, viewHeight);
            // #5 Wait until Chromium renders web page content.
            //waitEvent.WaitOne();
            // #6 Save Image of the loaded web page into a PNG file.

            //Create Save file dialog
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "PNG files (*.PNG)|*.PNG|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 1;
            saveFileDialog.RestoreDirectory = true;

            //Choose path and name to save the file
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Format name of file
                string imageFileName = saveFileDialog.FileName.ToString().Replace("%.png%", "");
                browserView1.GetImage().Save(imageFileName, ImageFormat.Png);
            }
            if (!browser.IsDisposed())
            {
                browserView1.Dispose();
                browser.Dispose();
            }
        }