Using VB for RGB colors in C#



Hi Cindy,

Thanks for giving this answer! It helped me solve my problem (I was coding in C# and needed an RGB color), and could do it easily using your solution.



Cindy M. wrote:

Re: How to set Word colors in c#?
18-Jun-08

I copied the following from the VSTO forum some time ago:

"You can't directly convert a System.Drawing.Color value to?its WdColor
equivalent.? The Font.Color property can be set to a WdColor value or the
result of the?VB RGB function.??The Microsoft.VisualBasic.Information.RGB()
method duplicates this function.? So you can do the following:

Code Snippet
rng.Font.Color = (Microsoft.Office.Interop.Word.WdColor)
Microsoft.VisualBasic.Information.RGB(0, 112, 192);


Note that this requires you reference?the Microsoft.VisualBasic assembly?from
your project.

You can also use the System.Drawing.ColorTranslator.ToOle() method.? This
doesn't require the reference to the Microsoft.VisualBasic assembly."

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

Previous Posts In This Thread:

On Tuesday, June 17, 2008 2:27 PM
Worduser200 wrote:

How to set Word colors in c#?
How to set Word color in c#? The only colors that I am able to set in Word
are in enumeration WdColor.
Word.WdColor color = Word.WdColor.wdColorTurquoise;

How can I set in c# shadings that are not in enumeration, for example
???Blue, Accent 1????


Thank you.

On Tuesday, June 17, 2008 2:42 PM
JeanGuyMarci wrote:

RE: How to set Word colors in c#?
"Word user 2007" wrote:


In VBA, you can use:

Selection.Range.Font.Color = RGB(10, 60, 165)

On Tuesday, June 17, 2008 3:28 PM
Worduser200 wrote:

RE: How to set Word colors in c#?
"Jean-Guy Marcil" wrote:



Is there any way to do it in C#?

On Tuesday, June 17, 2008 3:54 PM
JeanGuyMarci wrote:

RE: How to set Word colors in c#?
"Word user 2007" wrote:


I believe RGB is a VB function.

I do not know if there is an equivalent in C#.
This is a VBA group after all...

Try in:
microsoft.public.dotnet.languages.csharp

On Tuesday, June 17, 2008 6:44 PM
Tony Jollans wrote:

The 2007 Theme Colors are not RGB values.
The 2007 Theme Colors are not RGB values. The whole thing is described here:
http://www.wordarticles.com/Articles/Colours/2007.htm (well, maybe not the
whole thing yet, but it should be enough) - it gives VBA code but you can
use the same hex values in any language.

--
Enjoy,
Tony

"Jean-Guy Marcil" <JeanGuyMarcil@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2B878F08-9314-43FB-BB58-2C2AD1CED8A2@xxxxxxxxxxxxxxxx

On Wednesday, June 18, 2008 9:18 AM
Cindy M. wrote:

Re: How to set Word colors in c#?
I copied the following from the VSTO forum some time ago:

"You can't directly convert a System.Drawing.Color value to?its WdColor
equivalent.? The Font.Color property can be set to a WdColor value or the
result of the?VB RGB function.??The Microsoft.VisualBasic.Information.RGB()
method duplicates this function.? So you can do the following:

Code Snippet
rng.Font.Color = (Microsoft.Office.Interop.Word.WdColor)
Microsoft.VisualBasic.Information.RGB(0, 112, 192);


Note that this requires you reference?the Microsoft.VisualBasic assembly?from
your project.

You can also use the System.Drawing.ColorTranslator.ToOle() method.? This
doesn't require the reference to the Microsoft.VisualBasic assembly."

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

On Wednesday, June 18, 2008 12:37 PM
JeanGuyMarci wrote:

Re: How to set Word colors in c#?
"Tony Jollans" wrote:


Ha! I just noticed the "2007" in the poster alias...
I had just focused on the subject line...
I don't have 2007 on my machine at work and I am not all that good with
C#... Should've stayed away!

Thanks for jumping in!


Submitted via EggHeadCafe - Software Developer Portal of Choice
ASP.NET Multi-Lingual Language Translations
http://www.eggheadcafe.com/tutorials/aspnet/ce499f06-7466-4b3a-9d56-766a992561ef/aspnet-multilingual-lan.aspx
.