我的目标是在表单中有一个主要的richtextbox,然后在背景中有几个不同的richtextbox,背景文本框的所有时间都会在场景后面添加,删除和编辑......我需要一种方法将我的richtextbox在背景中使用richtextbox的表单。 我原来的东西是一本字典
Dictionary<string, RichTextBox> RichTextBoxs = new Dictionary<string, RichTextBox>();然后就走了
string Data = "string"; RichTextBox box = new RichTextBox(); box.Text = "Session for \""+Data+"\" started!"; box.Tag = (string)Data; RichTextBoxs.Add(Data, box);它可以很好地保存,但是当我尝试类似的时候
richTextBox1 = RichTextBoxs[(string)Data];什么都没发生! 我可以复制像属性
richTextBox1.Text = RichTextBoxs[(string)Data].Text;工作正常,但我需要复制所有的属性,以及我在文本框中的高级颜色格式。 我不知道为什么它不工作,因为据我了解它应该!
总结:我需要能够使用存储的文本框替换表单文本框
〜代码示例赞赏! 并提前致谢!
My goal is to have one main richtextbox in the form, and then several different richtextbox's in the backround, the backround textbox's get added, removed, and edited behind the scences all the time... and i need a way to swap my richtextbox in the form with the richtextbox's in the backround. what i origannally had was a Dictionary
Dictionary<string, RichTextBox> RichTextBoxs = new Dictionary<string, RichTextBox>();and would just go
string Data = "string"; RichTextBox box = new RichTextBox(); box.Text = "Session for \""+Data+"\" started!"; box.Tag = (string)Data; RichTextBoxs.Add(Data, box);and it saves fine, but the moment i try something like
richTextBox1 = RichTextBoxs[(string)Data];Nothing happens! i can copy over attributes like
richTextBox1.Text = RichTextBoxs[(string)Data].Text;works fine, but i need to copy ALL the properties, along with my advanced color formatting in the textbox's. i dont know why it isnt working, because as far as i know it should!
Summary: I need to be able to swap out form textbox's with stored textbox's
~code exampled appreciated! and thanks in advance!
最满意答案
要解决您的问题,您只需使用Rtf属性,而不是Text属性:
richTextBox1.Rtf = RichTextBoxs[(string)Data].Rtf;但我同意David Hay的看法,你应该直接在字典中存储Rtf字符串,而不是在另一个隐藏的RichTextBox中。
To solve your problem, you just need to use the Rtf property, not the Text property:
richTextBox1.Rtf = RichTextBoxs[(string)Data].Rtf;But I agree with David Hay that you should be storing the Rtf string directly in the Dictionary, not in another hidden RichTextBox.
更多推荐
发布评论