我如何使用RichTextBox控件?

时间:2022-10-30 12:05:51

I want my users to be able to enter text in a Rich Text box and the RTF output be saved to the database.

我希望我的用户能够在富文本框中输入文本,并将RTF输出保存到数据库中。

Currently I have the RichTextBox bound to the field in the database, but it strips formatting when it's saved. How can I prevent this?

目前我将RichTextBox绑定到数据库中的字段,但它在保存时会删除格式。我怎么能阻止这个?

Also, how can I attach a formatting toolbox, (like what's in Wordpad) so my users can change the formatting?

另外,如何附加格式化工具箱(如Wordpad中的内容),以便我的用户可以更改格式?

And, last, I can't right click in the box or use Ctrl+C, Ctrl+V or anything like that, why is that? How can I fix it?

最后,我不能右键单击框或使用Ctrl + C,Ctrl + V或类似的东西,为什么会这样?我该如何解决?

2 个解决方案

#1


Ok, there are alot of questions there, I'll try to answer what I can.

好的,那里有很多问题,我会尽力回答。

1) Databinding is great for displaying data, but I personally NEVER use DataBinding for saving stuff back to the database. I've always found it to be "too much magic happening" and that I needed more control. Therefore, I would strongly suggest that you handle the insertion yourself (via LINQ to Sql or ADO.Net whatever). The RichTextBox control has an RTF property which you can get to do the insert manually into the database.

1)数据绑定非常适合显示数据,但我个人从不使用DataBinding将内容保存回数据库。我总是发现它“发生了太多的魔法”,我需要更多的控制权。因此,我强烈建议您自己处理插入(通过LINQ to Sql或ADO.Net)。 RichTextBox控件具有RTF属性,您可以手动将其插入数据库。

2) As for getting formatting buttons on top, it's not as simple as changing a property and be done with it. You'll have to implement that custom control yourself. Have a look at this CodeProject article. IT's in VB.NET, but maybe it'll give you some ideas: http://www.vbdotnetheaven.com/UploadFile/scottlysle/WordProcessor09122006234320PM/WordProcessor.aspx

2)至于在顶部获取格式化按钮,它并不像更改属性那样简单并且完成它。您必须自己实现该自定义控件。看看这个CodeProject文章。它是在VB.NET中,但也许它会给你一些想法:http://www.vbdotnetheaven.com/UploadFile/scottlysle/WordProcessor09122006234320PM/WordProcessor.aspx

3) Not quite sure...

3)不太确定......

#2


For number 3, isn't there a property on the RichTextBox that enables the Context menu? I might've seen this on a different control but maybe it also has that property.

对于数字3,RichTextBox上是否有一个启用上下文菜单的属性?我可能已经在不同的控件上看到了这个,但也许它也有这个属性。

#1


Ok, there are alot of questions there, I'll try to answer what I can.

好的,那里有很多问题,我会尽力回答。

1) Databinding is great for displaying data, but I personally NEVER use DataBinding for saving stuff back to the database. I've always found it to be "too much magic happening" and that I needed more control. Therefore, I would strongly suggest that you handle the insertion yourself (via LINQ to Sql or ADO.Net whatever). The RichTextBox control has an RTF property which you can get to do the insert manually into the database.

1)数据绑定非常适合显示数据,但我个人从不使用DataBinding将内容保存回数据库。我总是发现它“发生了太多的魔法”,我需要更多的控制权。因此,我强烈建议您自己处理插入(通过LINQ to Sql或ADO.Net)。 RichTextBox控件具有RTF属性,您可以手动将其插入数据库。

2) As for getting formatting buttons on top, it's not as simple as changing a property and be done with it. You'll have to implement that custom control yourself. Have a look at this CodeProject article. IT's in VB.NET, but maybe it'll give you some ideas: http://www.vbdotnetheaven.com/UploadFile/scottlysle/WordProcessor09122006234320PM/WordProcessor.aspx

2)至于在顶部获取格式化按钮,它并不像更改属性那样简单并且完成它。您必须自己实现该自定义控件。看看这个CodeProject文章。它是在VB.NET中,但也许它会给你一些想法:http://www.vbdotnetheaven.com/UploadFile/scottlysle/WordProcessor09122006234320PM/WordProcessor.aspx

3) Not quite sure...

3)不太确定......

#2


For number 3, isn't there a property on the RichTextBox that enables the Context menu? I might've seen this on a different control but maybe it also has that property.

对于数字3,RichTextBox上是否有一个启用上下文菜单的属性?我可能已经在不同的控件上看到了这个,但也许它也有这个属性。