/// <summary>
///
/// </summary>
public partial class Form2 : Form
{ private mshtml.IHTMLDocument2 hc;
private mshtml.HTMLDocument hc1;
//subdir in ApplicationData Folder, change whatever you think
private const string M_WORKPATH = "someMCEenabledFolder";
//easilly navigate into resources
private const string M_RESOURCE = "WF_tinyMCE";
/// <summary>
///
/// </summary>
public override string Text
{
get
{
return m_text;
}
set
{
m_text = value;
}
}
/// <summary>
///
/// </summary>
/// <param name="source"></param>
/// <param name="target"></param>
public void CopyFile(Stream source, Stream target)
{
byte[] buffer = new byte[0x10000];
int bytes;
try
{
while ((bytes = source.Read(buffer, , buffer.Length)) > )
{
target.Write(buffer, , bytes);
}
}
finally
{
target.Close();
}
} /// <summary>
/// Get the correct internal path where tinyMCE and work file will be stored
/// </summary>
/// <param name="subPath"></param>
/// <returns></returns>
private string getWorkPath(string subPath)
{
string AppFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return System.IO.Path.Combine(AppFolder, M_WORKPATH + "\\" + subPath);
} private string m_strMCEDir = "";
private string m_strMCESettings = "";
/// <summary>
/// Prepare tinyMCE package
/// </summary>
public void PrepareTinyMCE()
{
string sCpy = getWorkPath("tinyMCE.zip");
m_strMCEDir = getWorkPath("tinyMCE");
m_strMCESettings = getWorkPath("tinyMCE.txt");
if (!Directory.Exists(getWorkPath("")))
{
Directory.CreateDirectory(getWorkPath(""));
} string sMCE = "tinyMCE\\tinyMCE\\jscripts\\tiny_mce";
if (!Directory.Exists(m_strMCEDir) || !File.Exists(getWorkPath(sMCE) + "\\tiny_mce.js"))
{
string sMce = M_RESOURCE + ".resources.tinyMCE.zip";
Stream strFile = GetResourceFile(sMce);
FileStream fs = new FileStream(sCpy, FileMode.OpenOrCreate);
CopyFile(strFile, fs);
strFile.Close(); Directory.CreateDirectory(m_strMCEDir);
FastZip fz = new FastZip();
fz.ExtractZip(sCpy, m_strMCEDir, FastZip.Overwrite.Never, null, null, null);
File.Delete(sCpy);
}
//settings
{
string sMce = M_RESOURCE + ".resources.tinyMCE.txt";
Stream strFile = GetResourceFile(sMce);
StreamReader sr = new StreamReader(strFile);
m_strMCESettings = sr.ReadToEnd();
sr.Close();
}
m_strMCEDir = sMCE;
}
/// <summary>
///
/// </summary>
/// <param name="File"></param>
/// <returns></returns>
public Stream GetResourceFile(string File)
{
if (File == null || File == "")
return null;
try
{
return this.GetType().Assembly.GetManifestResourceStream(File);
}
catch (Exception)
{
return null;
}
}
/// <summary>
///
/// </summary>
public void doInit()
{
object empty = System.Reflection.Missing.Value;
//mshtml.IHTMLDocument doc2 =webBrowser1.Document;
//IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webBrowser1.Document;
//webBrowser1.Document.Write("<html><body></body></html>");
//webBrowser1.Document.Body.innerHTML = "";//
//this.webBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty);
this.webBrowser1.Navigate("about:blank");
hc = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;//(mshtml.IHTMLDocument2) } private string m_text = "", m_type = "", m_css = "";
/// <summary>
///
/// </summary>
/// <param name="Text"></param>
public void ShowText(string Text)
{
m_text = Text;
showText(false);
this.Show();
//this.Dispose();
}
/// <summary>
///
/// </summary>
/// <param name="Text"></param>
/// <param name="Type"></param>
/// <param name="CSSFile"></param>
/// <returns></returns>
public string EditText(string Text, string Type, string CSSFile)
{
m_text = Text;
m_type = Type;
m_css = CSSFile;
PrepareTinyMCE();
showText(true);
this.ShowDialog();
m_text = ((mshtml.IHTMLDocument3)webBrowser1.Document.DomDocument).getElementById("elm1").innerText;
return m_text;
//this.Dispose();
} /// <summary>
///
/// </summary>
/// <param name="edit"></param>
private void showText(bool edit)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("<HTML><HEAD><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" content=\"no-cache\">");
if (edit && !string.IsNullOrEmpty(m_strMCESettings))
{
sb.Append("<script type=\"text/javascript\" src=\"");
sb.Append(this.m_strMCEDir.Replace('\\', '/')); //IE compatible
sb.AppendLine("/tiny_mce.js\">");
sb.AppendLine("</script>");
sb.AppendLine(this.m_strMCESettings);
sb.AppendLine("</HEAD><BODY><FONT FACE=\"Arial\" SIZE=\"-1\">");
sb.AppendLine("<form method=\"\" action=\"\" onsubmit=\"return false;\">");
sb.AppendLine("<textarea id=\"elm1\" name=\"elm1\" style=\"width: 100%;height:100%\">");
}
else
{
sb.AppendLine("</HEAD><BODY><FONT FACE=\"Arial\" SIZE=\"-1\">");
}
sb.AppendLine(m_text);
if (edit && !string.IsNullOrEmpty(m_strMCESettings))
{
sb.AppendLine("</textarea>");
}
sb.AppendLine("</FONT></BODY></HTML>"); //get CSS to local folder
if (File.Exists(m_css))
{
File.Copy(m_css, getWorkPath(m_type + ".css"), true);
m_css = m_type + ".css";
}
string t = sb.Replace("[CSS]", m_css).ToString();
string sDoc = getWorkPath(m_type + ".html");
StreamWriter sw = new StreamWriter(sDoc, false, System.Text.Encoding.GetEncoding());
sw.Write(t);
sw.Close();
try
{
this.webBrowser1.Navigate(sDoc);
}
catch (Exception e)
{
string s = e.Message;
}
}
/// <summary>
///
/// </summary>
public Form2()
{
InitializeComponent(); doInit();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form2_Load(object sender, EventArgs e)
{
//EditText("tinyMCE涂聚文 intergrated into .NET."
//+"A bit uncomfortable way through IE."
//+"But if you manage it good, you can use it for free."
//+"Don't forget to press save in MCE toolbar."
//+ "", "tempfilename", "yourCSS.css"); }
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
// MessageBox.Show(webBrowser1.Document.DomDocument.ToString());
string s = this.webBrowser1.Document.Body.InnerHtml;
string ss = this.webBrowser1.Document.Body.InnerText;
System.Windows.Forms.HtmlDocument document = this.webBrowser1.Document; //if (document != null && document.All["elm1"] != null && String.IsNullOrEmpty(document.All["elm1"].GetAttribute("value")))
//{
System.Windows.Forms.MessageBox.Show(document.All["elm1"].TagName.ToString());
System.Windows.Forms.MessageBox.Show(document.All["elm1"].OuterHtml);
//System.Windows.Forms.MessageBox.Show(document.All["elm1"].DomElement.ToString());
System.Windows.Forms.MessageBox.Show(document.All["elm1"].InnerText); System.Windows.Forms.MessageBox.Show(webBrowser1.Document.GetElementsByTagName("textarea")[].TagName);
// System.Windows.Forms.MessageBox.Show(document.All["elm1"].GetAttribute("value"));
//} //MessageBox.Show(webBrowser1.DocumentText);// HtmlElement textArea = webBrowser1.Document.All["elm1"]; HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("textarea");
foreach (HtmlElement element in elements)
{
if (element.InnerHtml.Contains("Rich text editor"))
{
// do something
}
}
}

Csharp:TinyMCE HTML Editor in .NET WindowsForms的更多相关文章

  1. Vue CLI 3+tinymce 5富文本编辑器整合

    基于Vue CLI 3脚手架搭建的项目整合tinymce 5富文本编辑器,vue cli 2版本及tinymce 4版本参考:https://blog.csdn.net/liub37/article/ ...

  2. 在 Vue 项目中引入 tinymce 富文本编辑器

    项目中原本使用的富文本编辑器是 wangEditor,这是一个很轻量.简洁编辑器 但是公司的业务升级,想要一个功能更全面的编辑器,我找了好久,目前常见的编辑器有这些: UEditor:百度前端的开源项 ...

  3. tinymce原装插件源码分析(二)-link

    link 功能描述如下: 单纯放置光标: 1.如果光标放到了<a>上,读取a标签的内容,并弹框显示,确定的时候,更新当前a标签. 2.否则,就创建弹框,确定的时候,按照参数添加a标签. s ...

  4. 富文本编辑器 tinymce 的安装与使用

    百度的富文本编辑器大家都熟悉,那么下面给大家介绍一款富文本编辑器tinymce ,个人感觉比百度的界面好看,调用方便,就不知道各位大神怎么看咯! tinymce中文文档 以下是vue中使用示例,献上最 ...

  5. 15、Vue CLI 3+tinymce 5富文本编辑器整合

    富文本编辑器里大佬们都说tinymce NB! 插件安装 inymce官方提供了一个vue的组件tinymce-vue 如果有注册或购买过服务的话,直接通过组件配置api-key直接使用,懒的注册或者 ...

  6. vue 配置 TinyMCE

    1.index.html 增加cdn 地址 <script src="//cdn.bootcss.com/tinymce/5.0.16/tinymce.min.js"> ...

  7. Vue tinymce富文本编辑器

    tinymce 官方为 vue 项目提供了一个组件 tinymce-vue 一.安装tinymce-vue npm install @tinymce/tinymce-vue -S 二.下载tinymc ...

  8. 富文本编辑器Tinymce的示例和配置

    Demo链接: https://download.csdn.net/download/silverbutter/10557703 有时候需要验证tinyMCE编辑器中的内容是否符合规范(不为空),就需 ...

  9. vue项目引入TinyMCE

    1.安装 npm install @tinymce/tinymce-vue@3.0.1 -S 2.配置 <template> <!-- 富文本 --> <div> ...

随机推荐

  1. Python基本数据类型集合、格式化、函数

    一.变量总结 1.1 变量定义 记录某种状态或者数值,并用某个名称代表这个数值或状态. 1.2 变量在内存中的表现形式 Python 中一切皆为对象,数字是对象,列表是对象,函数也是对象,任何东西都是 ...

  2. 搭建 docker + nginx + keepalived 实现Web应用的高可用(亲测)

    1. 环境准备     下载 VMware : https://www.vmware.com/go/getplayer-win        下载 Centos : https://mirrors.a ...

  3. Python3异常处理

    一. 简介 在编程过程中为了增加友好性,在程序出现Bug时一般不会直接将错误信息展示给用户,而是提供一个友好的输出提示. 二. 使用 1. 异常基础 常用结构: try: pass except Ex ...

  4. Reviewing notes 1.1 of Analytic geometry

    Chapter 1 Vector Algebra ♦ Vector Space Vector and vector space A vector is described as a quantity ...

  5. Servlet中Web.xml配置详解(二)

    5.2 分配JSP初始化参数给JSP页面提供初始化参数在三个方面不同于给servlet提供初始化参数.1)使用jsp-file而不是servlet-class.因此,WEB-INF/web.xml文件 ...

  6. [BZOJ 5415] 归程

    一棵KrusKal重构树,然而我数组开小了,忘记清空一个标记 洛谷传送门 BZOJ传送门 ......好像成权限题了Orz 回顾我们用KrusKal做生成树的时候,我们将边排序后连通各个连通块,那么边 ...

  7. 【算法笔记】B1046 划拳

    1046 划拳 (15 分) 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字.如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输 ...

  8. Oracle Pipelined Table Functions简介

    转自: http://www.linuxidc.com/Linux/2011-05/35797.htm //概况   //基本上,当你希望一个PLSQL(或者java或者c)程序作为数据源,而不是表, ...

  9. centos7.1部署java环境服务器

    1.检查操作系统自带java是jdk还是jre(否有javac,本例中没有javac) [root@bogon ~]# ls -l /usr/lib/jvm/总用量 0drwxr-xr-x. 3 ro ...

  10. html中一个div怎么引入另一个页面

    转载:https://zhidao.baidu.com/question/588973997598951645.html