예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        /// <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();
            }
        }
예제 #4
0
 /// <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>";
 }
예제 #5
0
        /// <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);
        }