Add a new class to your project and paste the code shown below. Compilation. Drop the new control on top of the tool window onto the form. Select the RichText property and click the dots button. This will launch Wordpad. Edit the text, type Ctrl + S and close Wordpad. Remember that the Visual Studio designer does not work while Wordpad is open.
Imports System.ComponentModel Imports System.Drawing.Design Imports System.IO Imports System.Diagnostics Public Class MyRtb Inherits RichTextBox <Editor(GetType(RtfEditor), GetType(UITypeEditor))> _ Public Property RichText() As String Get Return MyBase.Rtf End Get Set(ByVal value As String) MyBase.Rtf = value End Set End Property End Class Friend Class RtfEditor Inherits UITypeEditor Public Overrides Function GetEditStyle(ByVal context As ITypeDescriptorContext) As UITypeEditorEditStyle Return UITypeEditorEditStyle.Modal End Function Public Overrides Function EditValue(ByVal context As ITypeDescriptorContext, ByVal provider As IServiceProvider, ByVal value As Object) As Object Dim fname As String = Path.Combine(Path.GetTempPath, "text.rtf") File.WriteAllText(fname, CStr(value)) Process.Start("wordpad.exe", fname).WaitForExit() value = File.ReadAllText(fname) File.Delete(fname) Return value End Function End Class
Hans passant
source share