Change the Shape's Color

F

Fazoule

Hi,

I would to know how i can change the shape's Color with C#?

(when I right click on theshape -> format and here i can change the color)
 
F

Fazoule

Yep, i have already checked this site, but it don't work..
i ahve seen this example

Colour Test1: This subroutine will display and change the line colour and
the fill foreground colour of all the shapes on the current page.

Public Sub Colour_Test1()
Dim objshape As Visio.Shape
Dim i1 As Integer
For i1 = 1 To Visio.ActivePage.Shapes.Count
Set objshape = Visio.ActivePage.Shapes(i1)
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
objshape.Cells("LineColor") = 5
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
objshape.Cells("Fillforegnd") = 4
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
Next
End Sub

and in C# the shape.Cells doesn't exist..

i think it's a stuf like shape.get_cell(...) ??
but i don't if it's exactly this..
 
P

Paul Herber

Yep, i have already checked this site, but it don't work..
i ahve seen this example

Colour Test1: This subroutine will display and change the line colour and
the fill foreground colour of all the shapes on the current page.

Public Sub Colour_Test1()
Dim objshape As Visio.Shape
Dim i1 As Integer
For i1 = 1 To Visio.ActivePage.Shapes.Count
Set objshape = Visio.ActivePage.Shapes(i1)
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
objshape.Cells("LineColor") = 5
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
objshape.Cells("Fillforegnd") = 4
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
Next
End Sub

and in C# the shape.Cells doesn't exist..

Well, after you type the . after shape are you not presented with a
list of methods etc?
 
W

WapperDude

Are you committed to doing this in C#? This could be done in the shapesheet
with a little effort. Then, when you right click the shape, you can have a
menu that allows you to select a color. Avoids code and macros that way.

Wapperdude


Fazoule said:
Yep, i have already checked this site, but it don't work..
i ahve seen this example

Colour Test1: This subroutine will display and change the line colour and
the fill foreground colour of all the shapes on the current page.

Public Sub Colour_Test1()
Dim objshape As Visio.Shape
Dim i1 As Integer
For i1 = 1 To Visio.ActivePage.Shapes.Count
Set objshape = Visio.ActivePage.Shapes(i1)
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
objshape.Cells("LineColor") = 5
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
objshape.Cells("Fillforegnd") = 4
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
Next
End Sub

and in C# the shape.Cells doesn't exist..

i think it's a stuf like shape.get_cell(...) ??
but i don't if it's exactly this..
 
D

David Parker

Is it shape.get_Cells() in C# ?

Fazoule said:
Yep, i have already checked this site, but it don't work..
i ahve seen this example

Colour Test1: This subroutine will display and change the line colour and
the fill foreground colour of all the shapes on the current page.

Public Sub Colour_Test1()
Dim objshape As Visio.Shape
Dim i1 As Integer
For i1 = 1 To Visio.ActivePage.Shapes.Count
Set objshape = Visio.ActivePage.Shapes(i1)
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
objshape.Cells("LineColor") = 5
Debug.Print objshape.Name; " "; objshape.Cells("linecolor")
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
objshape.Cells("Fillforegnd") = 4
Debug.Print objshape.Name; " "; objshape.Cells("Fillforegnd")
Next
End Sub

and in C# the shape.Cells doesn't exist..

i think it's a stuf like shape.get_cell(...) ??
but i don't if it's exactly this..
 
F

Ferro Francesco

Is it shape.get_Cells() in C# ?


yep,

here what i make:

shape.get_CellsSRC(
(short)IVisio.VisSectionIndices.visSectionObject,
(short)IVisio.VisRowIndices.visRowFill,
(short)IVisio.VisCellIndices.visFillForegnd)
.FormulaU = "rgb(255,0,0)";

with this it's work, BUT the image is not updated... when i go on
"right-click->format->filling" the color of the FillForegnd is RED

how i can refresh the page?
 
P

Paul Herber

yep,

here what i make:

shape.get_CellsSRC(
(short)IVisio.VisSectionIndices.visSectionObject,
(short)IVisio.VisRowIndices.visRowFill,
(short)IVisio.VisCellIndices.visFillForegnd)
.FormulaU = "rgb(255,0,0)";

with this it's work, BUT the image is not updated... when i go on
"right-click->format->filling" the color of the FillForegnd is RED

how i can refresh the page?


try something like

Cell cellname;
cellname = shape.get_CellsSRC(
(short)IVisio.VisSectionIndices.visSectionObject,
(short)IVisio.VisRowIndices.visRowFill,
(short)IVisio.VisCellIndices.visFillForegnd);
cellname.FormulaU = "rgb(255,0,0)";
 
F

Ferro Francesco

try something like

Cell cellname;
cellname = shape.get_CellsSRC(
                 (short)IVisio.VisSectionIndices.visSectionObject,
                 (short)IVisio.VisRowIndices.visRowFill,
                 (short)IVisio.VisCellIndices.visFillForegnd);
cellname.FormulaU = "rgb(255,0,0)";


Same.. in the ShapeSheet (right click..) the FillForegnd is red, but
the visual shape color don't change
 
P

Paul Herber

Same.. in the ShapeSheet (right click..) the FillForegnd is red, but
the visual shape color don't change

Are you sure you have set the shape object correctly?
 
F

Ferro Francesco

Are you sure you have set the shape object correctly?

when i debut shape object is valid. (and the proof... the red color is
correctly set, but visio do not paint...)

i have coded this little method where cell = FillForegnd
private void applyFormulaToShapeAndChildren(Shape shape, string cell,
string
formula)
{
shape.get_CellsU(cell).FormulaU = formula;
foreach (Shape subShape in shape.Shapes)
{
if (0 == subShape.get_CellExistsU(cell,
(short)VisExistsFlags.visExistsLocally))
{
subShape.get_CellsU(cell).FormulaForceU = formula;
}
}
}

And it's work... the shape change color to red.. BUT it's strange...
why i must make this for paint... ?
 
F

Ferro Francesco

correction: don't work 2times...

example:
applyFormulaToShapeAndChildren(shape,"FillForegnd","RGB(255,0,0)");
applyFormulaToShapeAndChildren(shape,"FillForegnd","RGB(0,255,0)");


When i execute this, the shape turn to RED and next do not turn to
green.........
 
F

Ferro Francesco

hmmm. 2nd correct:

i have deleted this
if (0 == subShape.get_CellExistsU(cell,
(short)VisExistsFlags.visExistsLocally))
{

and now it's work :)

2nd question.. it's work in normal size, but if i put the document in
full page (f5) the color's shape don't change,,, and here, i have
realy no idea why
 
P

Paul Herber

when i debut shape object is valid. (and the proof... the red color is
correctly set, but visio do not paint...)

i have coded this little method where cell = FillForegnd
private void applyFormulaToShapeAndChildren(Shape shape, string cell,
string
formula)
{
shape.get_CellsU(cell).FormulaU = formula;
foreach (Shape subShape in shape.Shapes)
{
if (0 == subShape.get_CellExistsU(cell,
(short)VisExistsFlags.visExistsLocally))
{
subShape.get_CellsU(cell).FormulaForceU = formula;
}
}
}

Ah, a grouped shape, a very different kettle of fish.
Yes, the fill from the menu will fill a group's subshapes, in code you
have to do each subshape individually.
 

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