Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. dynamic RichTextBox accesing the Selection FontStyle

dynamic RichTextBox accesing the Selection FontStyle

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taen_Karth
    wrote on last edited by
    #1

    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

    C P 2 Replies Last reply
    0
    • T 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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

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

      T 1 Reply Last reply
      0
      • C Christian Graus

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

        T Offline
        T Offline
        Taen_Karth
        wrote on last edited by
        #3

        How in the world do I subscribe to the Selection changed event on the dynamic control. Somewhat new here... Thanks, Taen Karth

        C 1 Reply Last reply
        0
        • T Taen_Karth

          How in the world do I subscribe to the Selection changed event on the dynamic control. Somewhat new here... Thanks, Taen Karth

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

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

          T 1 Reply Last reply
          0
          • C Christian Graus

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

            T Offline
            T Offline
            Taen_Karth
            wrote on last edited by
            #5

            ok done some searching and still cannot find an answer... Would anyone else have any advice? Thanks, Taen Karth

            1 Reply Last reply
            0
            • T 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

              P Offline
              P Offline
              PranjalSharma
              wrote on last edited by
              #6

              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

              T 1 Reply Last reply
              0
              • P PranjalSharma

                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

                T Offline
                T Offline
                Taen_Karth
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups