Question SelectionFont is not a member of System.Windows.Controls.RichTextBox (?!)

benjeeqds

Member
Joined
Oct 2, 2008
Messages
9
Programming Experience
3-5
OK - I have a mystery...

I'm trying to set the RichTextBox text to bold (shouldn't be hard) but I've run into a funny problem where SelectionFont is not a member of System.Windows.Controls.RichTextBox.

I thought it was!

I'm using Visual Studio 2008 and desining the form in Expression Blend 2.


Be nice on me... this .NET stuff ain't my language!

How can I make the code below set the RichTextBox text and then set it to bold?


VB.NET:
Imports System
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Forms
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports System.Windows.Controls.RichTextBox
Imports System.Drawing
Imports Microsoft.VisualBasic

Partial Public Class ctlDocument
    Public Sub New()
        MyBase.New()

        Me.InitializeComponent()

        ' Insert code required on object creation below this point.
    End Sub
    Public Property TheTitle() As String
        Get
            Return txtTitle.Selection.Text
        End Get
        Set(ByVal value As String)
            txtTitle.SelectAll()
            txtTitle.Selection.Text = value
            
           '// the following lines are supposed to make the text bold, but they don't compile.
            Dim bfont As New Font(txtTitle.Font, FontStyle.Bold)
            txtTitle.SelectionFont = bfont


        End Set
    End Property
End Class

The errors follow:

Error 1 'Selectionfont' is not a member of 'System.Windows.Controls.RichTextBox'.
Error 2 'Font' is not a member of 'System.Windows.Controls.RichTextBox'.
Error 3 'Bold' is not a member of 'System.Windows.FontStyle'.
Error 4 'SelectionFont' is not a member of 'System.Windows.Controls.RichTextBox'.


Thanks heaps to anybody who can point me in the right direction!
 
The properties you mention is for the Windows.Forms RTB control, you should read the documentation for the Windows.Controls RTB control. Since you're formatting all text set FontWeight for the control, you can do this in designer Properties window.
 
Back
Top