本文介绍了WPF将.rtf文件从资源加载到RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我想加载.rtf文件的内容,确切地说,我已将其放入资源(通过Project-> Properties-> Resources-> Add File放入资源中,而我是WPF窗口应用程序)
我想将Agreement.rtf的内容加载到RichTextBox中,我尝试了以下操作
Hi, I am tying to load the content of a .rtf file, which i have put inside Resources (through Project->Properties->Resources->Add File, to be precise, and mine is a WPF window application)
I want to load Agreement.rtf''s content to a RichTextBox, i have tried the following
Dim stream As Stream
stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(My.Resources.ResourceManager.GetObject("Agreement").GetType(), "IOpzioni.Agreement.rtf")
RichTextBox1.SelectAll()
RichTextBox1.Selection.Load(stream, DataFormats.Rtf)
也
also
stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(My.Resources.Agreement.GetType(), "IOpzioni.Agreement.rtf")
IOpzioni是我的默认名称空间,我已经仔细检查了
但是似乎没有任何效果,
正确的方法是什么?
Where IOpzioni is my default namespace, i have doublechecked that
But nothing seems to work,
What is the correct Method to do this?
推荐答案
Using ms As New MemoryStream()
'' The following Resource Name will probably need to be adjusted.
Dim buffer as Byte() = Encoding.UTF8.GetBytes(My.Resources.IOpzioni.Agreement)
ms.Write(buffer, 0, buffer.Length)
ms.Seek(0, SeekOrigin.Begin)
RichTextBox1.LoadFile(ms, RichTextBoxStreamType.RichText)
End Using
这篇关于WPF将.rtf文件从资源加载到RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!