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 RichTextBox content

Getting ToolStrip button's CheckState to reflect RichTextBox content

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 are for aligning the text, i.e., Align Left, Center, Align Right. And two of the buttons are for increasing and decreasing Indentation. I have the CheckOnClick property set to true for these buttons. My application also has formatting buttons, i.e., Bold, Italic, Underlined and one button for setting a bulleted style. It was previously suggested that I use the RichTextBox_SelectionChanged event, which in fact works for the formatting buttons and Bullets button. However, I am running into a dead-end when attempting to write code for the alignment buttons or the 2-Indentation buttons. For example, when I try something like the following code:

    tsBtnAlignLeft.Checked = richTextBoxBody.SelectionAlignment;
    tsBtnAlignCtr.Checked = richTextBoxBody.SelectionAlignment;
    tsBtnAlignRight.Checked = richTextBoxBody.SelectionAlignment;

    it throws this exception: "Cannot implicitly convert type System.Windows.Forms.HorizontalAlignment' to 'bool'" And when I try to add further code in the RTB's SelectionChanged event for the IncreaseIndentation or DecreaseIndentation button's, i.e., tsbtnIncreaseIndent.Checked = richTextBoxBody.SelectionIndent; it throws the following exception: "Cannot implicitly convert type 'int' to 'bool'" Can anyone provide a suggestion for getting the Checked property of the alignment buttons and the indentation buttons to reflect the contents of the RichTextBox as the cursor moves over text that is aligned and\or indented? Thank you in advance. Richard

    C 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 are for aligning the text, i.e., Align Left, Center, Align Right. And two of the buttons are for increasing and decreasing Indentation. I have the CheckOnClick property set to true for these buttons. My application also has formatting buttons, i.e., Bold, Italic, Underlined and one button for setting a bulleted style. It was previously suggested that I use the RichTextBox_SelectionChanged event, which in fact works for the formatting buttons and Bullets button. However, I am running into a dead-end when attempting to write code for the alignment buttons or the 2-Indentation buttons. For example, when I try something like the following code:

      tsBtnAlignLeft.Checked = richTextBoxBody.SelectionAlignment;
      tsBtnAlignCtr.Checked = richTextBoxBody.SelectionAlignment;
      tsBtnAlignRight.Checked = richTextBoxBody.SelectionAlignment;

      it throws this exception: "Cannot implicitly convert type System.Windows.Forms.HorizontalAlignment' to 'bool'" And when I try to add further code in the RTB's SelectionChanged event for the IncreaseIndentation or DecreaseIndentation button's, i.e., tsbtnIncreaseIndent.Checked = richTextBoxBody.SelectionIndent; it throws the following exception: "Cannot implicitly convert type 'int' to 'bool'" Can anyone provide a suggestion for getting the Checked property of the alignment buttons and the indentation buttons to reflect the contents of the RichTextBox as the cursor moves over text that is aligned and\or indented? Thank you in advance. Richard

      C Offline
      C Offline
      Cassandra Ross
      wrote on last edited by
      #2

      In the SelectionChanged event you will need to analyze the selection alignment and set the Checked property of the left/right/centered buttons to suit. This is because the SelectionAlignment property can be more than just true or false (boolean), where the checked property is a boolean.

      U 1 Reply Last reply
      0
      • C Cassandra Ross

        In the SelectionChanged event you will need to analyze the selection alignment and set the Checked property of the left/right/centered buttons to suit. This is because the SelectionAlignment property can be more than just true or false (boolean), where the checked property is a boolean.

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

        Thanks Cassandra: I previously wasn't able to get the syntax to do what I needed to do. I just kept dancing around the issue in code, but couldn't quite get it right. That took care of it. Thanks for responding. 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