- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用这个 Converting between RTF and HTML来自 MSDN 的库,用于将一些 RTF 文本转换为 HTML。我的设置的要点是从 JavaScript 到 C# 处理程序的 AJAX 调用,该处理程序调用此 MarkupConverter
库进行转换,然后写回 HTML。
这是我的 JavaScript:
$.ajax({
type: "POST",
url: "MyHandler.ashx",
data: richTextData,
success: function (html) {
alert('success, html: ' + html);
},
error: function (msg) {
alert("error: " + msg);
}
});
public void ProcessRequest(HttpContext context)
{
if (context.Request.Form.Count > 0)
{
string rtf = context.Request.Form[0];
string html = "";
if (rtf != "")
{
markupConverter = new MarkupConverter.MarkupConverter();
html = markupConverter.ConvertRtfToHtml(rtf);
}
if (html != "")
{
context.Response.ContentType = "text/html";
context.Response.Write(html);
}
else
{
context.Response.ContentType = "text/plain";
context.Response.Write("Error from RTF2HTML");
}
}
}
RichTextBox
在后台线程上创建控件:
[InvalidOperationException: The calling thread must be STA, because many UI components require this.]
System.Windows.Input.InputManager..ctor() +11032206
System.Windows.Input.InputManager.GetCurrentInputManagerImpl() +125
System.Windows.Input.KeyboardNavigation..ctor() +185
System.Windows.FrameworkElement.EnsureFrameworkServices() +109
System.Windows.FrameworkElement..ctor() +504
System.Windows.Controls.Control..ctor() +87
System.Windows.Controls.RichTextBox..ctor(FlowDocument document) +56
MarkupConverter.RtfToHtmlConverter.ConvertRtfToXaml(String rtfText) +67 MarkupConverter.RtfToHtmlConverter.ConvertRtfToHtml(String rtfText) +23 MyHandler.ProcessRequest(HttpContext context) +416
var postText = $.ajax({
type: "POST",
url: "RTF2HTML.ashx",
data: textData,
async: false
}).responseText;
alert(postText);
context.Response.Write("thread: " + System.Threading.Thread.CurrentThread.GetApartmentState().ToString());
Response.Write
目前呢?
最佳答案
这可能有用:
How to run something in the STA thread?
也许你可以调用...
html = markupConverter.ConvertRtfToHtml(rtf);
string rtf;
public void ProcessRequest(HttpContext context)
{
if (context.Request.Form.Count > 0)
{
rtf = context.Request.Form[0];
string html = "";
if (rtf != "")
{
Thread thread = new Thread(ConvertMarkup);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
if (html != "")
{
context.Response.ContentType = "text/html";
context.Response.Write(html);
}
else
{
context.Response.ContentType = "text/plain";
context.Response.Write("Error from RTF2HTML");
}
}
}
void ConvertMarkup()
{
markupConverter = new MarkupConverter.MarkupConverter();
html = markupConverter.ConvertRtfToHtml(rtf);
}
关于c# - RichTextBox - InvalidOperationException : The calling thread must be STA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16194605/
我对 RichTextBox 控件感到困惑。 我的 WinForm 有一个 RichTextBox 控件,宽度为 100px。我想动态创建一个然后引用实例。 因此,假设在我的 Form 上我有一个名为
MouseDown 事件处理程序的 KeyDown 事件处理程序中 e.Handled = true 的等价物是什么?我不希望鼠标事件对 RichTextBox 有任何影响(完全禁用鼠标与 RichT
我有一个 richtextbox,它的文本是特定表格中一些单词的串联。 (表格列是'word','translate'和'id') 我需要当用户将鼠标悬停在每个单词上时,相关的翻译会显示在单词的工具提
您好,我在将 richtextbox 中的数据显示或传输到其他 richtextbox 时遇到问题... richtextbox1.Document = richtextbox2.Document;
我正尝试在我的 Windows Phone 8 应用程序中使用 RichTextBox。用户需要能够选择文本并将其复制到剪贴板。用户不需要编辑文本,只需选择它。但是,我似乎无法在 Windows Ph
我有一个 Winforms 项目,我可以在其中将文本写入 RichTextBox,还有一些控件可以设置所写文本的字体格式。我能够将文本保存并附加到 RTF 文件,但我在保留每个 RichTextBox
假设我有以下内容:
我需要一些具有富文本编辑功能的基本 CMS 功能。在 stack overflow 上有一个常规的文本区域编辑控件,支持 Markdown 样式语法格式。那将超出我的用户范围,所以我想要一个类似丰富的
显示图像: 复制代码代码如下: Image img = Image.FromFi
我遇到过 RichTextBox 的一些奇怪行为。我希望它是readonly,但是当我使用时它不显示图像richTextBox.LoadFile(path) 方法加载.rtf 文件。当它不是reado
我需要将 ScrollBars 设置为 ForcedBoth 但我还想知道 ScrollBars 的句柄何时可见并且用户可以滚动。 两个滚动条的 bool 值都可以 这里用户不能滚动: 在这里他们可以
我正在开发根据正则表达式模式在 RichTextBox 中突出显示文本的应用程序。 它工作正常,除了性能,即使对于小文本(大约 500 个字符),它也会挂起一段时间,这对用户是可见的。 我在 Flow
我在我的 WPF richtextbox 上启用了拼写,我想在显示带有拼写建议的上下文菜单之前在当前插入符号位置获取拼写错误的单词。 最佳答案 新方式 void richTextBox1_Pr
我在 .NET Windows 窗体应用程序中使用 RichTextBox 控件。我允许用户在文本框本身内按 TAB 键。但是,当我将 .Text 值保存在文本框中时,它将显示如下: "This[]i
我在 MS Word 中创建了带有超链接的 rtf 文件并将其加载到 RichTextBox 中。 RichTextBox 中的超链接不起作用。 RichTextBox 和 MS Word 使用不同的
有没有办法改变 RichTextBox 中下划线的颜色? ? 我试过 this但它似乎不起作用。有人知道这些枚举值是从哪里来的吗?没有看到它的任何文档。 谢谢。 最佳答案 枚举值是将消息传递给控件时的
这是交易:我有一个 RichTextBox 控件,它工作正常。问题是有一个“插入当前日期时间”按钮,它将当前日期时间添加/注入(inject)到 RichTextBox 中。用户可以在插入符号指向的任
我正在编写一个小应用程序,我可以在其中加载文本文件以匹配正则表达式: 我根据匹配行的长度更改前景色文本, 问题是,如果一行是多行,那么它不会按预期工作并且只选择该行的一半,例如以“title”开头的第
我有一个 RichTextBox在我的应用程序中,它正在获取有关某些事件的新内容。 添加新内容时,我想滚动到底部,仅当 卷轴在底部 之前 . 我该怎么做呢? 更具体地说,给我带来麻烦的部分是确定滚动位
当加载 50KB 的文本文档时,WPF 的 RichTextBox 控件的性能确实很慢。滚动滞后并按 Ctrl-A 选择所有文本需要 10 多秒钟。 (这在记事本上是瞬时的)。 我没有做任何花哨的位图
我是一名优秀的程序员,十分优秀!