473,473 Members | 4,204 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

conversion from VB to C#

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
Nov 16 '05 #1
2 1040
"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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
Nov 16 '05 #2
Thanks a lot, Stefan.

Sakharam Phapale

"Stefan Simek" <si********@kascomp.blah.sk> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
"Sakharam Phapale" <sp******@annetsite.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
7
by: Michael Lehn | last post by:
Hi, I have a question regarding the conversion of objects. When is the conversion done by the constructor and when by the operator. My feeling tells me that the constructor is preferred. But...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: Steve Richter | last post by:
here is a warning I am getting in a C++ .NET compile: c:\SrNet\jury\JuryTest.cpp(55) : warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied while...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: dataentryoffshore | last post by:
Get a Discount up to 60% on data entry, data capture, dataentry services, large volume data processing and data conversion services through offshore facilities in India. Offshore data entry also...
21
by: REH | last post by:
It it permissible to use the constructor style cast with primitives such as "unsigned long"? One of my compilers accepts this syntax, the other does not. The failing one chokes on the fact that the...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.