conversion from VB to C#

S

Sakharam Phapale

Hi All,

I am new in C#.
Please tell me, how to convert following statements.
(Change font style to Bold and vice-versa)

Dim fOld As Font = myRichTextBox.SelectionFont
Dim fStyle As FontStyle = fOld.Style + (IIf(fOld.Bold, FontStyle.Bold * -1,
FontStyle.Bold))

myRichTextBox.SelectionFont = New Font(fOld.FontFamily, fOld.Size, fStyle)

Thanks and Regards,
Sakharam Phapale
 
S

Stefan Simek

Sakharam Phapale said:
Hi All,

I am new in C#.
Please tell me, how to convert following statements.
(Change font style to Bold and vice-versa)

Dim fOld As Font = myRichTextBox.SelectionFont
Font fOld = myRichTextBox.SelectionFont;
Dim fStyle As FontStyle = fOld.Style + (IIf(fOld.Bold, FontStyle.Bold
* -1,
FontStyle.Bold))
FontStyle fStyle = fOld.Style ^ FontStyle.Bold;
myRichTextBox.SelectionFont = New Font(fOld.FontFamily, fOld.Size, fStyle)
myRichTextBox.SelectionFont = new Font(fOld.FontFamily, fOld.Size, fStyle);
Thanks and Regards,
Sakharam Phapale

The above is more or less a transcription of your VB code. I would prefer
much simpler code:

Font fOld = myRichTextBox.SelectionFont;
myRichTextBox.SelectionFont = new Font(fOld, fOld.Style ^ FontStyle.Bold);

HTH,
Stefan
 
S

Sakharam Phapale

Thanks a lot, Stefan.

Sakharam Phapale

Stefan Simek said:
Font fOld = myRichTextBox.SelectionFont;

FontStyle fStyle = fOld.Style ^ FontStyle.Bold;
fStyle)
myRichTextBox.SelectionFont = new Font(fOld.FontFamily, fOld.Size, fStyle);

The above is more or less a transcription of your VB code. I would prefer
much simpler code:

Font fOld = myRichTextBox.SelectionFont;
myRichTextBox.SelectionFont = new Font(fOld, fOld.Style ^ FontStyle.Bold);

HTH,
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top