Change color of shape

M

Marco

I'm aware about reports that the Visio 2003 .NET/C# SDK will be
released somewhere Q1-2004. However I'm hoping that somebody can give
me a hint beforehand how to achieve to change the color of a shape
programmatically.

I got it working to find the selected Visio shape. And I can change
the text, however I don't have the slightest idea how to change the
color of the shape.

Maybe through SetFormula() but I don't understand what the arguments
are

//this works:
this.selectedShape.Text = visio_term + " exists";

//but what is SRCStream and formulaArray?
this.selectedShape.SetFormulas(ref SRCStream, ref formulaArray, 0);

The documentation does not reveal more then

public abstract new System.Int16 SetFormulas ( System.Array
SRCStream , System.Array formulaArray , System.Int16 Flags )
Member of Microsoft.Office.Interop.Visio.IVShape

Any one has a clue?

Marco
 
M

Marco

This worked for ME:

private void SetColor(Visio.Shape shape)
{
// Set the fill color, line color, and hyperlink.
try
{
System.Array sourceStream = Array.CreateInstance(typeof(short), 9);

sourceStream.SetValue((short) Visio.VisSectionIndices.visSectionObject, 0);
sourceStream.SetValue((short) Visio.VisRowIndices.visRowFill,1);
sourceStream.SetValue((short) Visio.VisCellIndices.visFillForegnd,2);

sourceStream.SetValue((short) Visio.VisSectionIndices.visSectionObject, 3);
sourceStream.SetValue((short) Visio.VisRowIndices.visRowLine, 4);
sourceStream.SetValue((short) Visio.VisCellIndices.visLineColor, 5);

sourceStream.SetValue((short) Visio.VisSectionIndices.visSectionHyperlink, 6);
sourceStream.SetValue((short) Visio.VisRowIndices.visRow1stHyperlink, 7);
sourceStream.SetValue((short) Visio.VisCellIndices.visHLinkAddress, 8);
//+ Visio.tagVisCellIndices.hyperlink.Row
//;
System.Array formula = Array.CreateInstance(typeof(object), 3);

formula.SetValue("3",0); //green
formula.SetValue("4",1); //blue
formula.SetValue(VisioHelper.StringToFormulaForString("test"), 2);

shape.SetFormulas(ref sourceStream, ref formula, 0);
}
catch (Exception any)
{
MessageBox.Show(any.Message);
MessageBox.Show(any.StackTrace);
}
 

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