private void exportToHTMLToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "HTML with <PRE> tag|*.html|HTML without <PRE> tag|*.html"; if (sfd.ShowDialog() == DialogResult.OK) { string html = ""; if (sfd.FilterIndex == 1) { html = synBox1.Html; } if (sfd.FilterIndex == 2) { ExportToHTML exporter = new ExportToHTML(); exporter.UseBr = true; exporter.UseNbsp = false; exporter.UseForwardNbsp = true; exporter.UseStyleTag = true; html = exporter.GetHtml(synBox1); } File.WriteAllText(sfd.FileName, html); } }
internal void ExportHtml() { var tb = GetSelectedTabEditor(); if (tb != null) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "HTML with <PRE> tag|*.html|HTML without <PRE> tag|*.html"; if (sfd.ShowDialog() == DialogResult.OK) { string html = ""; if (sfd.FilterIndex == 1) { html = tb.Html; } if (sfd.FilterIndex == 2) { ExportToHTML export = new ExportToHTML(); export.UseBr = true; export.UseStyleTag = true; html = export.GetHtml(tb); } File.WriteAllText(sfd.FileName, html); } } }
/// <summary> /// Copy selected text into Clipboard /// </summary> public static void Copy(FastColoredTextBox textbox) { if (textbox.Selection.IsEmpty) { textbox.Selection.Expand(); } if (!textbox.Selection.IsEmpty) { var exp = new ExportToHTML(); exp.UseBr = false; exp.UseNbsp = false; exp.UseStyleTag = true; string html = "<pre>" + exp.GetHtml(textbox.Selection.Clone()) + "</pre>"; var data = new DataObject(); data.SetData(DataFormats.UnicodeText, true, textbox.Selection.Text); data.SetData(DataFormats.Html, PrepareHtmlForClipboard(html)); data.SetData(DataFormats.Rtf, new ExportToRTF().GetRtf(textbox.Selection.Clone())); // var thread = new Thread(() => SetClipboard(data)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); } }
/// <summary> /// Gets colored text as HTML /// </summary> /// <remarks>For more flexibility you can use ExportToHTML class also</remarks> public static string GetHtml(FastColoredTextBox textbox) { var exporter = new ExportToHTML(); exporter.UseNbsp = false; exporter.UseStyleTag = false; exporter.UseBr = false; return "<pre>" + exporter.GetHtml(textbox) + "</pre>"; }
/// <summary> /// Prints range of text /// </summary> public static void Print(FastColoredTextBox textbox, Range range, PrintDialogSettings settings) { //prepare export with wordwrapping var exporter = new ExportToHTML(); exporter.UseBr = true; exporter.UseForwardNbsp = true; exporter.UseNbsp = true; exporter.UseStyleTag = false; exporter.IncludeLineNumbers = settings.IncludeLineNumbers; if (range == null) range = textbox.Range; if (range.Text == string.Empty) return; //change visible range textbox.visibleRange = range; try { //call handlers for VisibleRange textbox.CallVisibleRangeHandlers(); } finally { //restore visible range textbox.visibleRange = null; } //generate HTML string HTML = exporter.GetHtml(range); HTML = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"><head><title>" + PrepareHtmlText(settings.Title) + "</title></head>" + HTML + "<br>" + SelectHTMLRangeScript(textbox); string tempFile = Path.GetTempPath() + "fctb.html"; File.WriteAllText(tempFile, HTML); //clear wb page setup settings SetPageSetupSettings(settings); //create wb var wb = new WebBrowser(); wb.Tag = settings; wb.Visible = false; wb.Location = new Point(-1000, -1000); wb.Parent = textbox; wb.StatusTextChanged += wb_StatusTextChanged; wb.Navigate(tempFile); }