vartan
Member
Hi, I'm new to this forum.
I have a problem with my Windows application.
I have an MDI form that creates a new child form when the new button is clicked. The child form contains a rich text box called CRTB which is made to fill the whole child form:
Then when a button on the MDI form with the caption Bold is clicked, it runs this:
VB tells me that CRTB.SelectionFont.Bold is Read Only and that I cannot change its value.
How do I set the selection of the text to be bold?
Many thanks to anyone who can help me.
P.S. I have attached the project in a compressed folder (.zip) format.
I have a problem with my Windows application.
I have an MDI form that creates a new child form when the new button is clicked. The child form contains a rich text box called CRTB which is made to fill the whole child form:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] ShowNewForm([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
[/SIZE][SIZE=2][COLOR=#008000]' Create a new instance of the child form.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ChildForm [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.Form
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] CRTB [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.RichTextBox
[/SIZE][SIZE=2][COLOR=#008000]'Dim CRTB As New System.Windows.Forms.RichTextBox
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Make it a child of this MDI form before showing it.
[/COLOR][/SIZE][SIZE=2]ChildForm.MdiParent = [/SIZE][SIZE=2][COLOR=#0000ff]Me
[/COLOR][/SIZE][SIZE=2]m_ChildFormNumber += 1
ChildForm.Text = [/SIZE][SIZE=2][COLOR=#800000]"Window "[/COLOR][/SIZE][SIZE=2] & m_ChildFormNumber
CRTB.Dock = DockStyle.Fill
CRTB.Parent = ChildForm
ChildForm.Show()
[COLOR=seagreen]'CRTB.Text = [/COLOR][/SIZE][SIZE=2][COLOR=seagreen]"Hello!"[/COLOR]
[/SIZE][COLOR=seagreen][SIZE=2]'CRTB.SaveFile([/SIZE][SIZE=2]"format.rtf"[/SIZE][/COLOR][SIZE=2][COLOR=seagreen])[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
Then when a button on the MDI form with the caption Bold is clicked, it runs this:
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] BoldBut_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] BoldBut.Click
[/SIZE][SIZE=2][COLOR=#0000ff]For [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] ChildForm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Form [/SIZE][SIZE=2][COLOR=#0000ff]In [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].MdiChildren
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] ChildForm.ContainsFocus [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] CRTB [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] RichTextBox [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] ChildForm.Controls
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] CRTB.SelectionFont.Bold <> [/SIZE][SIZE=2][COLOR=#0000ff]False [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]CRTB.SelectionFont.Bold = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else [/COLOR][/SIZE]
[COLOR=black]CRTB.SelectionFont.Bold = [/COLOR][COLOR=blue]False[/COLOR]
[COLOR=blue]End If[/COLOR][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
VB tells me that CRTB.SelectionFont.Bold is Read Only and that I cannot change its value.
How do I set the selection of the text to be bold?
Many thanks to anyone who can help me.
P.S. I have attached the project in a compressed folder (.zip) format.