H
Hariharan S
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.
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.