Is text style possible in richtextbox at design time?

I have a System.Windows.Forms.RichTextBox that I want to use to display some instructions for users of my application.

Is it possible to set part of the text that I entered during development to make it bold?

Or I don't have an option, but for this at runtime?

+6
visual-studio richtextbox design-time
source share
4 answers

You can create an RTF document in an RTF editor (for example, WordPad), save the file, open it as a text / plain file and copy the RTF document to the RtfText property of your RichTextBox during development.

But I advise against this. So you have a lot of data in your code, and they just have nothing to do. In the end, use the resource for what it is needed. You can bind individual resources to manage properties during development.

+2
source share

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 
+7
source share

I found this codeproject link very useful:

http://www.codeproject.com/KB/miscctrl/richtextboxextended.aspx

This is a fully working rtf edit control around the standard .net RichtTextBox control with good structured code. It shows how to use almost all the available functions of a control.

However, this is written in C #, not vb.net, but you should definitely take a look.

+1
source share

Bravo - simple and effective! There is also a slight correction, because the argument is a long string with spaces, so the next line contains the required quotation marks:

 Process.Start("wordpad.exe", """" & fname & """").WaitForExit() 
0
source share

All Articles