Getting ToolStrip button's CheckState to reflect text formatting
-
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
-
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
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 :)
-
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 :)
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