Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » GDI+ » Applications » Downloads
 
Add your own
alternative version
Go to top

A Professional HTML Renderer You Will Use

, 29 Jan 2009
100% managed code that draws HTML on any device
HtmlDemo.002.zip
System.Drawing.Html.dll
Html Demo.exe
HtmlDemo.zip
System.Drawing.Html.dll
Html Demo.exe
System.Drawing.Html.002.zip
System.Drawing.Html
Html Demo
bin
Debug
Html Demo.exe
Html Demo.vshost.exe
HtmlDemo.zip
System.Drawing.Html.dll
Html Demo.csproj.user
Properties
Settings.settings
Resources
comment16.gif
delete16.gif
delete32.gif
exclamation32.png
favorites32.png
font32.png
formula32.png
image32.png
method16.gif
paly32.png
property16.gif
property32.png
refreshdocument32.png
web_pallete.gif
Window.gif
Samples
System.Drawing.Html.suo
System.Drawing.Html
bin
Debug
System.Drawing.Html.dll
System.Drawing.Html.vshost.exe
Properties
Settings.settings
System.Drawing.Html.zip
Html Demo.exe
Html Demo.vshost.exe
System.Drawing.Html.dll
Html Demo.csproj.user
Settings.settings
comment16.gif
delete16.gif
delete32.gif
exclamation32.png
favorites32.png
font32.png
formula32.png
image32.png
method16.gif
paly32.png
property16.gif
property32.png
refreshdocument32.png
web_pallete.gif
Window.gif
System.Drawing.Html.suo
System.Drawing.Html.dll
System.Drawing.Html.vshost.exe
Settings.settings
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Html;
using System.Reflection;
using System.IO;

namespace Html_Demo
{
    public partial class MainForm : Form
    {
        #region Fields
        private const int MAX = 5;
        private int tmrCount = 0;
        private bool updateLock = false;
        #endregion

        #region Ctor
        public MainForm()
        {
            InitializeComponent();

            //Rtf font
            rtf.Font = new Font(FontFamily.GenericMonospace, 10);

            //Window bounds
            StartPosition = FormStartPosition.Manual; Bounds = Screen.GetWorkingArea(Point.Empty);

            //Load samples
            LoadSamples();
        } 
        #endregion

        #region Methods

        /// <summary>
        /// Loads the tree of document samples
        /// </summary>
        private void LoadSamples()
        {
            TreeNode root = new TreeNode("Sample Documents"); tv.Nodes.Add(root);
            string[] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            string extensionFilter = ".htm";

            Array.Sort(names);

            foreach (string name in names)
            {
                int extPos = name.LastIndexOf('.');
                int namePos = extPos > 0 && name.Length > 1 ? name.LastIndexOf('.', extPos - 1) : 0;
                string ext = name.Substring(extPos >= 0 ? extPos : 0);
                string shortName = namePos > 0 && name.Length > 2 ? name.Substring(namePos + 1, name.Length - namePos - ext.Length - 1) : name;

                if (string.IsNullOrEmpty(extensionFilter)
                    || extensionFilter.IndexOf(ext) >= 0)
                {
                    TreeNode node = new TreeNode(shortName);
                    root.Nodes.Add(node);
                    node.Tag = name;
                }
            }
           
            root.Expand();

            if (root.Nodes.Count > 0)
            {
                tv.SelectedNode = root.Nodes[0];
                tv_NodeMouseClick(this, new TreeNodeMouseClickEventArgs(root.Nodes[0], MouseButtons.None, 0, 0, 0));
            }
        }

        #endregion

        private void rtf_TextChanged(object sender, EventArgs e)
        {
            if (updateLock) return;

            tmrCount = 0;
            tmrRepaint.Enabled = true;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            string resource = Convert.ToString(e.Node.Tag);

            if (string.IsNullOrEmpty(resource)) return;

            using (StreamReader sreader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resource), Encoding.Default))
            {
                
                string html = sreader.ReadToEnd();
                SyntaxHilight.AddColoredText(html, rtf);

                updateLock = true;
                Application.UseWaitCursor = true;
                panel.Text = html;
                Application.UseWaitCursor = false;
                updateLock = false;
            }

            
            
        }

        private void colorPicker1_ColorSelected(object sender, EventArgs e)
        {
            Color c = colorPicker1.SelectedColor;
            rtf.SelectedText = string.Format("#{0}{1}{2}", 
                (c.R < 10 ? "0" : string.Empty) +  c.R.ToString("x"),
                (c.G < 10 ? "0" : string.Empty) + c.G.ToString("x"),
                (c.B < 10 ? "0" : string.Empty) + c.B.ToString("x"));
        }

        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.C)
            {
                colorPicker1.Visible = !colorPicker1.Visible;
                e.Handled = true;
                e.SuppressKeyPress = true;
            }
        }

        private void tmrRepaint_Tick(object sender, EventArgs e)
        {
            tmrCount++;

            if (tmrCount >= MAX)
            {
                tmrCount = 0;
                tmrRepaint.Enabled = false;
                panel.Text = rtf.Text;
                Console.WriteLine("Parse");
            }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

Jose Menendez Póo
Team Leader
Mexico Mexico
I'm in game programming now: https://itunes.apple.com/us/app/ugly-aliens-training-center/id859271884?ls=1&mt=8
 
Jose Manuel Menéndez Poó
 
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is user interface usability.
 
Questions and stuff by twitter: @menendezpoo
 
Blog
menendezpoo.com

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 30 Jan 2009
Article Copyright 2009 by Jose Menendez Póo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid