473,421 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Font change ...

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
2 8736
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: hzgt9b | last post by:
Using VS 2003, VB.NET: I have a TreeView control filled with TreeNodes. When I create the TreeView, I set HotTracking = True. Subsequently, I change the font (make the not bold versus bold) on...
0
by: Jon Davis | last post by:
It looks like (looks like! ... not that there is!) there's a bug in the TreeNode object. When you change the font, it does not readjust its size appropriately. The following code shows the...
0
by: Dan Neely | last post by:
Winform labels, buttons, etc don't respond to the normal/large/extra large font settings that can be specified in display properties. Is there an easy way to do an appwide detection+change at...
1
by: Rajesh Joshi | last post by:
How to Change Datagrid's Column font change for a column. and How fill Msflexgrid fill with particular Recordset at runtime.
2
by: Jim | last post by:
Working with VB.net under VS.Net 2003. Have a simple form with a Button1. I want to change the font on the button when the button is clicked. Is there a way to Dynamically change the Font for...
0
by: Dhans | last post by:
I have a MDI Application. From the container form I am setting the font for the each controls in the MDI Child form. If I increase the size of the font greater than the default, the text in each...
1
by: ChillUmesh | last post by:
can i change font in message box. if so can u help me out in this thnx
4
by: Polaris | last post by:
Hi Experts: I'm using asp.net 2.0. Is there a way for my pages not to respond to the IE's Page-Text Size? Thanks in advance! Polaris
1
by: Andrus | last post by:
I need to save font selected by user by Ctrl+MouseWheel in Winforms RichTextBox. I tried override below but this does not remember font: in this method Font.Size property seems to be always...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.