469,357 Members | 1,832 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,357 developers. It's quick & easy.

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

nicebasic
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
CommandButtonBold
CommandButtonItalics
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 CommandButtonBold 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:
Expand|Select|Wrap|Line Numbers
  1. Screen.ActiveControl

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

Any help regarding this problem will be appreciated.
Dec 16 '11 #1

✓ answered by Killer42

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.

3 1857
Killer42
8,435 Expert 8TB
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.
Dec 18 '11 #2
Thank you very much. You're quite right.

I think SelChange, GotFocus, and LostFocus could help.

I'll try it.
Dec 20 '11 #3
Killer42
8,435 Expert 8TB
Glad we could help. Please let us know how it turns out.
Dec 20 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Imaya Kumar | last post: by
1 post views Thread by Piotrek Stachowicz | last post: by
6 posts views Thread by Radith Silva | last post: by
5 posts views Thread by cs_hart | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.