如何在Powershell RichTextBox中显示.rtf文件

时间:2010-06-24 20:07:10

标签: powershell richtextbox rtf

我想在Powershell RichTextBox中显示RTF文件的内容。

我正在尝试制作一种自定义EULA,最简单的方法是将内容写入RTF文件,然后将其显示在表单上的RichTextBox中,这样用户就必须单击一个复选框接受它。

(我确定它位于ServerFault和StackOverflow之间,但我猜这里的DotNet大师会知道最好的。;-))

干杯,

2 个答案:

答案 0 :(得分:4)

如果其他人发生这种想法,PowerShell RichTextBox control来自哪里,它是对System.Windows.Forms中的那个的引用。这是具有先决条件构建的代码:

[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.LoadFile($path)

答案 1 :(得分:1)

好的 - 这很容易。在张贴之前,我应该在谷歌上多点放一些懒惰的屁股。使用了RichTextFile.Loadfile(c:\myfile.rtf)并且它有效。