dynamic RichTextBox accesing the Selection FontStyle
-
I have a dynamically created RichTextBox control. I also have ToolStripButton for setting the selction string to Bold in the box. What I need to do is be able to catch the selected texts FontStyle as it is selected. i.e. MS Word has the feature that when you click on text that is Bold the bold toolbar icon is checked and when you click on regular text it is not checked. How would I capture the Fontstyle in realtime on a dynamically created control? I hope this makes sense. Thanks, Taen Karth
-
I have a dynamically created RichTextBox control. I also have ToolStripButton for setting the selction string to Bold in the box. What I need to do is be able to catch the selected texts FontStyle as it is selected. i.e. MS Word has the feature that when you click on text that is Bold the bold toolbar icon is checked and when you click on regular text it is not checked. How would I capture the Fontstyle in realtime on a dynamically created control? I hope this makes sense. Thanks, Taen Karth
You need to subscribe to the selection changed event, then hopefully you can examine the selected text for it's font properties. Christian Graus - Microsoft MVP - C++
-
You need to subscribe to the selection changed event, then hopefully you can examine the selected text for it's font properties. Christian Graus - Microsoft MVP - C++
How in the world do I subscribe to the Selection changed event on the dynamic control. Somewhat new here... Thanks, Taen Karth
-
How in the world do I subscribe to the Selection changed event on the dynamic control. Somewhat new here... Thanks, Taen Karth
I don't use VB, I hate it. If you're using VB.NET, there has been some discussion on events on dynamic controls in the past day or so, search the forum for details. Christian Graus - Microsoft MVP - C++
-
I don't use VB, I hate it. If you're using VB.NET, there has been some discussion on events on dynamic controls in the past day or so, search the forum for details. Christian Graus - Microsoft MVP - C++
ok done some searching and still cannot find an answer... Would anyone else have any advice? Thanks, Taen Karth
-
I have a dynamically created RichTextBox control. I also have ToolStripButton for setting the selction string to Bold in the box. What I need to do is be able to catch the selected texts FontStyle as it is selected. i.e. MS Word has the feature that when you click on text that is Bold the bold toolbar icon is checked and when you click on regular text it is not checked. How would I capture the Fontstyle in realtime on a dynamically created control? I hope this makes sense. Thanks, Taen Karth
ok you try doing in this way create a handler which handles selection change event. when you have created the RTB assign handler you created to it by using AddHandler In SelectionChange handler use this code If sender.SelectionFont.Bold = True Then Me.CheckBox1.Checked = True Else Me.CheckBox1.Checked = False End If if you have selected a text which has a bold text then checkbox would be checked other wise not checked. (Keep a check box on form) ---------------------------------------- Here's The code 'handles RTB's Selection Change Event Private Sub RTB_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) If sender.SelectionFont.Bold = True Then Me.CheckBox1.Checked = True Else Me.CheckBox1.Checked = False End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim txt As New RichTextBox 'Define A New RTB txt.Size = New Size(100, 100) txt.Location = New Point(0, 0) Me.Controls.Add(txt) 'Add RTB To Form AddHandler txt.SelectionChanged, AddressOf Me.RTB_SelectionChanged 'Assign SelctionChange Event Handler End Sub Pranjal Sharma
-
ok you try doing in this way create a handler which handles selection change event. when you have created the RTB assign handler you created to it by using AddHandler In SelectionChange handler use this code If sender.SelectionFont.Bold = True Then Me.CheckBox1.Checked = True Else Me.CheckBox1.Checked = False End If if you have selected a text which has a bold text then checkbox would be checked other wise not checked. (Keep a check box on form) ---------------------------------------- Here's The code 'handles RTB's Selection Change Event Private Sub RTB_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) If sender.SelectionFont.Bold = True Then Me.CheckBox1.Checked = True Else Me.CheckBox1.Checked = False End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim txt As New RichTextBox 'Define A New RTB txt.Size = New Size(100, 100) txt.Location = New Point(0, 0) Me.Controls.Add(txt) 'Add RTB To Form AddHandler txt.SelectionChanged, AddressOf Me.RTB_SelectionChanged 'Assign SelctionChange Event Handler End Sub Pranjal Sharma
did I mention you are the man! hehe I completely forgot about AddHandler. Your code led me in the right direction. I extended it of course and put it in a module but it works great. Once again thanks for the heads up! Thanks, Taen Karth