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. C#
  4. Getting ToolStrip button's CheckState to reflect text formatting

Getting ToolStrip button's CheckState to reflect text formatting

Scheduled Pinned Locked Moved C#
csharptutorialquestion
3 Posts 2 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.
  • U Offline
    U Offline
    User 2628354
    wrote on last edited by
    #1

    Dear Sirs: I have a C# application with a ToolStrip control and a RichTextBox control. Three of the buttons on the toolStrip are for formatting the text in the RichTextBox, i.e., Bold, Italic, and Underlined. I have the CheckOnClick property set to true for these 3-buttons. My code successfully sets the selected text to any\all of the above formatting. However, the button's CheckState remains "Pressed" or clicked, unless I physically unclick it. What I want to do is emulate what occurs in a WordPad document, where by both scrolling over formatted text, or clicking into formatted text causes the Bold button, Italic button, or Underline button(s) to appear depressed or clicked and conversely, to not appear depressed or clicked when the user clicks outside of the formatted text or scrolls past it. Does anyone know how to accomplish this in C# and also what event(s) to place this code in, so that this happens smoothly for the end-user? Thank you in advance for your answer Richard

    L 1 Reply Last reply
    0
    • U User 2628354

      Dear Sirs: I have a C# application with a ToolStrip control and a RichTextBox control. Three of the buttons on the toolStrip are for formatting the text in the RichTextBox, i.e., Bold, Italic, and Underlined. I have the CheckOnClick property set to true for these 3-buttons. My code successfully sets the selected text to any\all of the above formatting. However, the button's CheckState remains "Pressed" or clicked, unless I physically unclick it. What I want to do is emulate what occurs in a WordPad document, where by both scrolling over formatted text, or clicking into formatted text causes the Bold button, Italic button, or Underline button(s) to appear depressed or clicked and conversely, to not appear depressed or clicked when the user clicks outside of the formatted text or scrolls past it. Does anyone know how to accomplish this in C# and also what event(s) to place this code in, so that this happens smoothly for the end-user? Thank you in advance for your answer Richard

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      private void richEdit_SelectionChanged(object sender, EventArgs e)
      {
      if (richEdit.SelectionFont != null)
      {
      ButtonBold.Checked = richEdit.SelectionFont.Bold;
      ButtonItalic.Checked = richEdit.SelectionFont.Italic;
      ButtonUnderline.Checked = richEdit.SelectionFont.Underline;
      }
      }

      Enjoy :)

      I are troll :)

      U 1 Reply Last reply
      0
      • L Lost User

        private void richEdit_SelectionChanged(object sender, EventArgs e)
        {
        if (richEdit.SelectionFont != null)
        {
        ButtonBold.Checked = richEdit.SelectionFont.Bold;
        ButtonItalic.Checked = richEdit.SelectionFont.Italic;
        ButtonUnderline.Checked = richEdit.SelectionFont.Underline;
        }
        }

        Enjoy :)

        I are troll :)

        U Offline
        U Offline
        User 2628354
        wrote on last edited by
        #3

        Hello Eddy: Thanks a lot for your reply. The code gives me exactly what I was looking for and works great. I didn't know how to accomplish this but was fairly certain it could be done. Also, I wasn't sure which event to call it in. Your submission is very much appreciated. Thanks again. Richard

        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