将(Rich)TextBox的内容保存到内存中并使用C#中的RichTextBox将其关闭(Saving (Rich)TextBox's to memory and switching th

编程入门 行业动态 更新时间:2024-10-18 20:25:08
将(Rich)TextBox的内容保存到内存中并使用C#中的RichTextBox将其关闭(Saving (Rich)TextBox's to memory and switching them off with a richtextbox in my form in C#)

我的目标是在表单中有一个主要的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.

更多推荐

本文发布于:2023-08-01 17:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361499.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将其   内存   内容   RichTextBox   Rich

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!