set FillColor per c#

H

Helmut Fischer

Hi,

I would like to set the FillColor of a Shape per c# and I am trying this
with the following function:

public void SetBackgroundColor(Visio.Shape shape)
{
ArrayList sourceStream = new ArrayList();
ArrayList formula = new ArrayList();

sourceStream.Add((short)Visio.VisSectionIndices.visSectionObject);
sourceStream.Add((short)Visio.VisRowIndices.visRowFill);
sourceStream.Add((short)Visio.VisCellIndices.visFillForegnd);

formula.Add("RGB(255,0,0)");

Array arrSourceStream = sourceStream.ToArray(typeof(short));
Array arrFormula = formula.ToArray();

shape.SetFormulas(ref arrSourceStream, ref arrFormula, 0);

}

Unfortunately I am getting a meaningfull comException that says "Exception
occurred". I have tested it with the "Prozess"-Shape in "C:\Program
Files\Microsoft Office\Office12\1031\BASFLO_M.VSS" (Yes, the german one),
but also with different other shapes, all with the same error. I have also
tried a wrong value ("GB(255,0,0)"), then the Exception says "Unknown
function name", so it seems as if the RGB-Function is recognized.

I have written several of those functions to set specific Shape properties
like width or position. All of them work correctly, only this one does not.
I have installed the Visio 2007 Service Pack, hoping that this could bring
the solution, but without success.

Anyone out there with an idea?

Thanks a lot in advance, Helmut
 
M

Mark Nelson [MS]

Two things you might try:

First, does it work when you pass visSetUniversalSyntax in the Flags
argument of SetFormulas? You should definitely be working with universal
names and syntax when programmatically modifying formulas. Otherwise you
run the risk that Visio will interpret your comma as a decimal point instead
of an argument separator.

Second, does it work when you specify a built-in color index such as 3
instead of the RGB() function? This would confirm whether that the cell is
properly handling your input.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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