Saving formatted text from richtextbox

2019-07-16 04:49发布

问题:

Is there any way, to save formatted in database from richtextbox?

I've got richtextbox and some parts of text in this are bold.

string s=richtextbox.Text obviously doesn't work.

And If I can get this formatted text how to save it in Ms Sql Server 2005 ?

回答1:

Try using this to get the text and all rich text format codes.

string s = richTextBox.Rtf;


回答2:

There is one way to save the formatting to a database. I don't know what database system you use but you simply have to save all of the formatting properties- which are mostly alpha-numeric- in fields named the same as the properties themselves, in one single location, then each time your form loads also load these fields into their associated properties of the richtextbox control, from the database table. You can't name it Properties however. An odbc data source name can be automatically created connecting you to the database...but that is off the subject. But you do this using some dataset that you can save and update. But you can even save text colors and styles in this table.