private void WebBrowser_LoadCompleted(object sender, NavigationEventArgs e) { string css = "body { margin:0; padding:0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 11px; }"; string script = "document.body.style.overflow ='hidden'"; WebBrowser wb = (WebBrowser)sender; wb.InvokeScript("execScript", new Object[] { script, "JavaScript" }); mshtml.HTMLDocument CurrentDocument = (mshtml.HTMLDocument)wb.Document; mshtml.IHTMLStyleSheet styleSheet = CurrentDocument.createStyleSheet("", 0); styleSheet.cssText = css; }
public HtmlEditorControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // define the context menu for format commands DefineFormatBlockMenu(); // define the default values // browser constants and commands EMPTY_PARAMETER = System.Reflection.Missing.Value; // default values used to reset values _defaultBackColor = Color.White; _defaultForeColor = Color.Black; _defaultFont = new HtmlFontProperty(this.Font); // set browser default values to hide IE items this.editorWebBrowser.AddressBar = false; this.editorWebBrowser.MenuBar = false; this.editorWebBrowser.StatusBar = false; // obtain the underlying web browser and set options // SHDocVw.WebBrowser webBrowser = (SHDocVw.WebBrowser)this.editorWebBrowser.GetOcx(); // define the default values of the properties _readOnly = false; _toolbarVisible = false; _enableVisualStyles = false; _toolbarDock = DockStyle.Bottom; _bodyText = DEFAULT_HTML_TEXT; _bodyHtml = DEFAULT_HTML_TEXT; _bodyBackColor = _defaultBackColor; _bodyForeColor = _defaultForeColor; _bodyFont = _defaultFont; _scrollBars = DisplayScrollBarOption.Auto; _imageDirectory = string.Empty; _htmlDirectory = string.Empty; _navigateWindow = NavigateActionOption.Default; _baseHref = string.Empty; _autoWordWrap = true; stylesheet = null; script = null; // define context menu state this.menuDocumentToolbar.Checked = true; this.menuDocumentScrollbar.Checked = true; this.menuDocumentWordwrap.Checked = true; // load the blank Html page to load the MsHtml object model BrowserCodeNavigate(BLANK_HTML_PAGE); // after load ensure document marked as editable this.ReadOnly = _readOnly; }
/// <summary> /// Private control constructor defining all default values /// </summary> public HtmlEditorControl() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // define the default values // browser constants and commands EMPTY_PARAMETER = System.Reflection.Missing.Value; // default values used to reset values _defaultBodyBackColor = Color.White; _defaultBodyForeColor = Color.Black; _defaultBackColor = SystemColors.ControlLight; _defaultFont = new HtmlFontProperty(this.Font); // define the default values of the properties _readOnly = false; _toolbarVisible = true; _toolbarDock = DockStyle.Bottom; _bodyText = DEFAULT_HTML_TEXT; _bodyHtml = DEFAULT_HTML_TEXT; _bodyBackColor = _defaultBodyBackColor; _bodyForeColor = _defaultBodyForeColor; _bodyFont = _defaultFont; _scrollBars = DisplayScrollBarOption.Auto; _imageDirectory = string.Empty; _htmlDirectory = string.Empty; _navigateWindow = NavigateActionOption.Default; _baseHref = string.Empty; _autoWordWrap = true; _borderSize = DEFAULT_BORDER_SIZE; stylesheet = null; script = null; // define context menu state and size this.BackColor = _defaultBackColor; this.contextDocumentToolbar.Checked = true; this.contextDocumentScrollbar.Checked = true; this.contextDocumentWordwrap.Checked = true; SetBrowserPanelSize(); // load the blank Html page to load the MsHtml object model BrowserCodeNavigate(BLANK_HTML_PAGE); // after load ensure document marked as editable this.ReadOnly = _readOnly; this.ScrollBars = _scrollBars; }
// define the style sheet to be used for editing // can be used for standard templates public void LinkStyleSheet(string stylesheetHref) { if (stylesheet != null) { // if (document.styleSheets.length > 0) // Create an IEnumerator for the cells of the row // IEnumerator enumerator = document.styleSheets.GetEnumerator(); // enumerator.MoveNext(); // stylesheet = (HtmlStyleSheet)enumerator.Current; stylesheet.href = stylesheetHref; } else { stylesheet = (HtmlStyleSheet)document.createStyleSheet(stylesheetHref, 0); } }