By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,088 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,088 IT Pros & Developers. It's quick & easy.

Font change ...

P: n/a
Hi Guys,

Have an issue with the Font object.

I have a text box in which I can enter text and I have included a small
button which upon selection, should enable me to change the newly entered
text into bold. But it is not what is happening. All the previous
information entered in the regular font too gets changed to bold. The code
on the button click event handler is as follows ...

Note: A Font object is created as a Font object cannot be assigned values.

public void btnBold_Click(object sender, System.EventArgs e)
{
Font oldFont = Font;
FontStyle newStyle = Font.Style ^ FontStyle.Bold;
Font = new Font(oldFont, newStyle);
oldFont.Dispose();
}

This is a code copied from Mickey Williams' Visual C# .NET text book (see
page 470). What I require is only the text that is going to be entered in
the text box after the selection of the btnBold should appear as 'bold' and
the earlier text already present in the textbox. The textbox used is
'RichTextBox' as the regular text box does not provide these facilities.

Example: a RichTextBox below ...
---------------------------------------------------------------------------
| This is just to demonstrate what I expect. Let us say, I want the text
|
| to be bold from this point
|
---------------------------------------------------------------------------

The moment, I type any character after the ' point ' in the above
RichTextBox after selecting the 'bold' option, all the characters from the '
This ' too gets changed to bold. That is something, I do not want.

Any help on this would be appreciated. Awaiting response at the earliest and
would be grateful.

p.s. Do not want to use the FontDialog to change my Font.
---

Regards,
Hariharan S

Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Are you using a richtexbox yourself?
If you use a regular textbox the font applies to all text.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2

P: n/a
Hey Hariharan,

You would use the RichTextBox's "SelectionFont" property to accomplish your
task. Say your RichTextBox was named "rtf", then use something like this
code:

private void btnBold_Click(object sender, System.EventArgs e)
{
rtf.SelectionFont = new Font(rtf.Font, FontStyle.Bold);
}

Good luck!

-Noah Coad
Microsoft MVP & MCP
"Hariharan S" <fr********@televital.com> wrote in message
news:ex**************@TK2MSFTNGP12.phx.gbl...
Hi Guys,

Have an issue with the Font object.

I have a text box in which I can enter text and I have included a small
button which upon selection, should enable me to change the newly entered
text into bold. But it is not what is happening. All the previous
information entered in the regular font too gets changed to bold. The code
on the button click event handler is as follows ...

Note: A Font object is created as a Font object cannot be assigned values.

public void btnBold_Click(object sender, System.EventArgs e)
{
Font oldFont = Font;
FontStyle newStyle = Font.Style ^ FontStyle.Bold;
Font = new Font(oldFont, newStyle);
oldFont.Dispose();
}

This is a code copied from Mickey Williams' Visual C# .NET text book (see
page 470). What I require is only the text that is going to be entered in
the text box after the selection of the btnBold should appear as 'bold' and the earlier text already present in the textbox. The textbox used is
'RichTextBox' as the regular text box does not provide these facilities.

Example: a RichTextBox below ...
-------------------------------------------------------------------------- - | This is just to demonstrate what I expect. Let us say, I want the text |
| to be bold from this point
|
-------------------------------------------------------------------------- -
The moment, I type any character after the ' point ' in the above
RichTextBox after selecting the 'bold' option, all the characters from the ' This ' too gets changed to bold. That is something, I do not want.

Any help on this would be appreciated. Awaiting response at the earliest and would be grateful.

p.s. Do not want to use the FontDialog to change my Font.
---

Regards,
Hariharan S

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.