PDA

View Full Version : کامپوننت html Editor برای winApplication



memo_mojtab
سه شنبه 22 فروردین 1391, 18:32 عصر
سلام
از دوستان میخواستم در رابطه با ایجاد کامپوننت html Editor برای winApplication منو راهنمایی کنند!
با تشکر!

h-rafiee
سه شنبه 22 فروردین 1391, 22:53 عصر
سلام دوست عزیز.

برای این کار باید فیال کتابخانه ای زیر رو به پروژه ات اضافه کنی

85554

و بعد کدها به صورت زیر است


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTG.Html;

namespace CreateHtmlDoc
{
class Program
{
static string indent = "";

static void Main(string[] args)
{
string htmltext = "<div><b>Bold text</b> before <span style=\"font-style:italic;\">Italic text</span></div>";

// Build DOM of the html
HtmlDoc html = HtmlDoc.ParseHTML(htmltext);

// The function changes text style from italic to underline
ScanHtmlTree(html.Nodes);

// Show the tree of the html
ViewHtmlDOM(html.Nodes);
Console.ReadLine();
}

static void ScanHtmlTree(HtmlNodeCollection nodes)
{
foreach (HtmlNode node in nodes)
{
if (node.IsElement)
{
HtmlTag tag = node as HtmlTag;
if (tag.Attributes.IndexOf("style") != -1)
tag.Attributes["style"].Value = "text-decoration:underline;";

ScanHtmlTree(tag.Nodes);
}
}
}

static void ViewHtmlDOM(HtmlNodeCollection nodes)
{
foreach (HtmlNode node in nodes)
{
if (node.IsText)
{
HtmlText text = node as HtmlText;
Console.WriteLine(indent + text.ToString());
}
else
{
HtmlTag tag = node as HtmlTag;
Console.WriteLine(indent + tag.ToString());

indent += " ";
ViewHtmlDOM(tag.Nodes);

indent = indent.Substring(0, indent.Length - 2);
Console.WriteLine(indent + "</" + tag.Name + ">");
}
}
}

}
}


منبع :
http://www.devtriogroup.com/HtmlParser/