How to Set Text to Bold or Italics on a Multiple-RichTextBox Form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nicebasic
    New Member
    • Aug 2010
    • 91

    How to Set Text to Bold or Italics on a Multiple-RichTextBox Form?

    Hello everybody,

    I have a form on which I have several RichTextBoxes. Now, I'd like to be able to set text to Bold or Italics in each of these RichTextBoxes. On a given form like the following, we have these elements:

    FormMain
    CommandButtonBo ld
    CommandButtonIt alics
    RichTextBox1
    RichTextBox2
    RichTextBox3
    RichTextBox4

    If we select (=highlight) some text in one of these RichTextBoxes and press one of the above Command Buttons, how can we determine which RichTextBox should be the target of this formatting? For example, we select (=highlight) some text in RichTextBox1 and then, we press CommandButtonBo ld to set the selected text to Bold. How can we know that the selected text in RichTextBox1 needs to be formatted? When another control gets focused, all the RichTextBoxes will lose focus.

    When you select some text in a RichTextBox, it is the Active Control at that time. But if you press a Control that receives focus, the RichTextBox loses focus and another control will become the Active Control.

    We can determine which control is Active at a given time using this command:
    Code:
    Screen.ActiveControl

    But I don't know how to handle this problem.

    Any help regarding this problem will be appreciated.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    What I'd suggest is that you go to the SelChange or GotFocus event for each RichTextBox control, and place a value in some variable that tells you which one it is. Then, when a button is clicked, look at that variable to determine which one to work with.

    I believe you'd want to define this as a form-level variable (that is, in the (General) - (Declarations) section of the form so that it's available to everything in the form.

    Comment

    • nicebasic
      New Member
      • Aug 2010
      • 91

      #3
      Thank you very much. You're quite right.

      I think SelChange, GotFocus, and LostFocus could help.

      I'll try it.

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Glad we could help. Please let us know how it turns out.

        Comment

        Working...