Exemplo n.º 1
0
        public BitmapImage GetImage()
        {
            BitmapImage result = null;
            if (ImageAllowed)
            {
                using (var browser = new System.Windows.Forms.WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = true;
                    browser.ScrollBarsEnabled = false;
                    browser.DocumentCompleted += (s, e) =>
                    {

                        var width = browser.Document.InvokeScript("eval", new object[] { @"
            function documentWidth(){
            return Math.max(
            document.documentElement['clientWidth'],
            document.body['scrollWidth'], document.documentElement['scrollWidth'],
            document.body['offsetWidth'], document.documentElement['offsetWidth']
            );
            }
            documentWidth();
            "});
                        var height = browser.Document.InvokeScript("eval", new object[] { @"
            function documentHeight(){
            return Math.max(
            document.documentElement['clientHeight'],
            document.body['scrollHeight'], document.documentElement['scrollHeight'],
            document.body['offsetHeight'], document.documentElement['offsetHeight']
            );
            }
            documentHeight();
            "});

                        if (height != null && width != null)
                        {
                            browser.Height = int.Parse(height.ToString());
                            browser.Width = int.Parse(width.ToString());
                            using (var pic = new Bitmap(browser.Width, browser.Height))
                            {

                                browser.Focus();
                                browser.DrawToBitmap(pic, new System.Drawing.Rectangle(0, 0, pic.Width, pic.Height));
                                var strm = new MemoryStream();
                                pic.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                                strm.Seek(0, SeekOrigin.Begin);
                                result = new BitmapImage();
                                result.BeginInit();
                                result.StreamSource = strm;
                                result.DecodePixelHeight = 300;
                                result.EndInit();
                            }
                        }
                        else
                        {
                            result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
                        }
                    };

                    browser.Navigate(_url);
                    while (browser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
            }
            else
            {
                result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
            }
            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// タブページ追加
        /// </summary>
        /// <param name="url">URL</param>
        private void AddTabWindow(string url)
        {
            var newPage = new TabPage();
            var newBrowser = new WebBrowser();

            //WebBrowserコントロール各種設定
            newBrowser.Dock = DockStyle.Fill;
            newBrowser.ScriptErrorsSuppressed = true;

            //イベントフック
            newBrowser.DocumentTitleChanged += new EventHandler(webBrowser_DocumentTitleChanged);
            newBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
            newBrowser.StatusTextChanged += new EventHandler(webBrowser_StatusTextChanged);
            newBrowser.Navigated += new WebBrowserNavigatedEventHandler(webBrowser_Navigated);
            newBrowser.ProgressChanged += new WebBrowserProgressChangedEventHandler(webBrowser_ProgressChanged);
            newBrowser.NewWindow += new CancelEventHandler(webBrowser_NewWindow);

            //ブラウザコントロールをタブページに追加
            newPage.Controls.Add(newBrowser);

            //タブページ追加
            this.tabControl1.TabPages.Add(newPage);

            this.tabControl1.SelectedTab = newPage;

            //初期表示HPへナビゲート
            this.Navigate(url);

            newBrowser.Focus();
        }
Exemplo n.º 3
0
        public BitmapImage GetImage()
        {
            BitmapImage result = null;

            if (ImageAllowed)
            {
                using (var browser = new System.Windows.Forms.WebBrowser())
                {
                    browser.ScriptErrorsSuppressed = true;
                    browser.ScrollBarsEnabled      = false;
                    browser.DocumentCompleted     += (s, e) =>
                    {
                        var width  = browser.Document.InvokeScript("eval", new object[] { @"
function documentWidth(){
	return Math.max(
		document.documentElement['clientWidth'],
		document.body['scrollWidth'], document.documentElement['scrollWidth'],
		document.body['offsetWidth'], document.documentElement['offsetWidth']
	);
}
documentWidth();
" });
                        var height = browser.Document.InvokeScript("eval", new object[] { @"
function documentHeight(){
	return Math.max(
		document.documentElement['clientHeight'],
		document.body['scrollHeight'], document.documentElement['scrollHeight'],
		document.body['offsetHeight'], document.documentElement['offsetHeight']
	);
}
documentHeight();
" });

                        if (height != null && width != null)
                        {
                            browser.Height = int.Parse(height.ToString());
                            browser.Width  = int.Parse(width.ToString());
                            using (var pic = new Bitmap(browser.Width, browser.Height))
                            {
                                browser.Focus();
                                browser.DrawToBitmap(pic, new System.Drawing.Rectangle(0, 0, pic.Width, pic.Height));
                                var strm = new MemoryStream();
                                pic.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                                strm.Seek(0, SeekOrigin.Begin);
                                result = new BitmapImage();
                                result.BeginInit();
                                result.StreamSource      = strm;
                                result.DecodePixelHeight = 300;
                                result.EndInit();
                            }
                        }
                        else
                        {
                            result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
                        }
                    };

                    browser.Navigate(_url);
                    while (browser.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                    {
                        System.Windows.Forms.Application.DoEvents();
                    }
                }
            }
            else
            {
                result = new System.Windows.Media.Imaging.BitmapImage(new Uri(_url));
            }
            return(result);
        }
Exemplo n.º 4
0
 private void BrowseUrl(string url)
 {
     _webBrowser.Focus();
     _webBrowser.Navigate(url);
 }
Exemplo n.º 5
0
 public override void setFocus()
 {
     pb.Focus();
 }
Exemplo n.º 6
0
 private void MODRefPage_MouseEnter(object sender, EventArgs e)
 {
     webBrowser.Focus();
 }