存储在数据库中时保留 RichText 格式吗?
我创建了一个富文本框,将“textBox.Text”值存储在 SDF 数据库中。 存储有效,但格式似乎丢失了。 这是SDF数据库无法处理的事情吗? 我需要以二进制形式存储吗? 也不知道该怎么做。
我正在使用 Visual Basic Express Edition 和 Winforms 并在 VisualBasic.NET 中编写 顺便说一句,
这就是我存储到数据库的方式:
Private Sub btnToolStripSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolStripSave.Click
Try
Me.Validate()
Me.SangerBindingSource.EndEdit()
Me.SangerTableAdapter.Update(Me.MusicBaseDBDataSet.Sanger)
Me.MusicBaseDBDataSet.Sanger.AcceptChanges()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
这就是我将文本插入到富文本框中的方式
txtBoxText.SelectionFont = New Font("Verdana", 16, FontStyle.Bold)
txtBoxText.SelectionColor = System.Drawing.Color.RoyalBlue
txtBoxText.SelectionLength = 0
txtBoxText.SelectedText = btnA.Text & btnB.Text & " "
txtBoxText.SelectionFont = New Font("Verdana", 12, FontStyle.Regular)
txtBoxText.SelectionColor = System.Drawing.Color.Black
I've created a rich text box which stored the "textBox.Text" value in an SDF database. The storing works, but the formatting seems to be lost. Is this something that SDF databases can't handle? Do I need to store in binary or something? Not sure how to do that either.
I'm using Visual Basic Express Edition with Winforms and writing in VisualBasic.NET btw
This is how I store to the database:
Private Sub btnToolStripSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToolStripSave.Click
Try
Me.Validate()
Me.SangerBindingSource.EndEdit()
Me.SangerTableAdapter.Update(Me.MusicBaseDBDataSet.Sanger)
Me.MusicBaseDBDataSet.Sanger.AcceptChanges()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
And this is how I insert the text in to the rich textbox
txtBoxText.SelectionFont = New Font("Verdana", 16, FontStyle.Bold)
txtBoxText.SelectionColor = System.Drawing.Color.RoyalBlue
txtBoxText.SelectionLength = 0
txtBoxText.SelectedText = btnA.Text & btnB.Text & " "
txtBoxText.SelectionFont = New Font("Verdana", 12, FontStyle.Regular)
txtBoxText.SelectionColor = System.Drawing.Color.Black
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用
RichTextBox.Text
属性:这会删除格式。 使用RichTextBox.Rtf
属性。Don't use the
RichTextBox.Text
property: that removes the formatting. Use theRichTextBox.Rtf
property.转到
txtBoxText
的属性。 展开 (DataBindings) 元素后,您应该能够将绑定从Text
属性更改为Rtf
Go to the properties of
txtBoxText
. After expanding the (DataBindings) element, you should be able to change the binding from theText
property toRtf