views:

487

answers:

1

hi, i am using vsto, to work with excel-2007...

let's consider i have a matrix as follows

     A    B    C
 1  10   11    12
 2  10   12    11
 3  11   10    12

i will always read some random matrix filled with random numbers... ex above, and the other condition is that they will also be colored randomly according to the same numbers, for ex. in the above case cells which contain 10 will be colored red, those with 11 will be colored green, and so on...

now i have to put some kind of panel on a worksheet which will show info of this kind

rectangle with RED color  - 10
rectangle with GREEN color - 11
rectangle with BLUE color  - 12

i tried to do it with charts, but unfortunately did not succeed,... i cannot put those info on a range of cells, that's not a solution i am looking for,... i have to put it on some kind of panel, so that user will be able to drag the panel wherever they want, ..

i have no idea how to do it, please can you suggest me a way how create smth kind of panel and to put that info there... Thanks!

sorry for not mentioning this, iwant to be able to put rectangles inside the panel, so that whenever i move the panel all the components of the panel should move together... also i do not want user to be able to modify the contents of the panel, they should only be able to move the panel only...

+1  A: 

For text only, a textbox would probably do the trick.

If you definitely need rectangles, you could construct several drawing objects: filled-in Rectangles for the coloured rectangles, textboxes for the descriptions and a Rectangle with a white background to act as a frame for the legend. Once drawn, you could Group them which would turn them into a single object from the users' POV.

Here's a edited example from MSDN I've converted to C# and tested:

Excel.Worksheet ex = (Excel.Worksheet)Application.ActiveSheet;
ex.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeIsoscelesTriangle, 10, 10, 100, 100).Name = "shpOne";
ex.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeIsoscelesTriangle, 150, 10, 100, 100).Name = "shpTwo";
ex.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeIsoscelesTriangle, 300, 10, 100, 100).Name = "shpThree";
object[] shapeArray = {"shpOne", "shpTwo", "shpThree"};
Excel.ShapeRange rng = ex.Shapes.get_Range(shapeArray);
Excel.Shape grp = rng.Group();

This creates three triangles that are linked together - the user would drag them around as if a single object.

Joel Goodwin
how can i put rectangle inside the textbox?
Ah... you can't, I was thinking the contents were text only. Changing my answer for an alternative...
Joel Goodwin
hi thanks a lot, is it possible to make the components of the legend unchangeable, only draggable...?
what i mean is user can change the color and size of the triangles, which i don't want... is it possible?
I don't think so seagull; the only way you can really lock down a graphic is to draw an image in C# and put that on the sheet as a Picture object, rather than using composite Excel drawing objects to build it. The only other option is to protect the sheet, which unfortunately prevents the object being dragged as well.
Joel Goodwin
thanks a lot! goodgai
hi goodgai how is it possible to change the backcolor of one of the above shapes.... for example shpOne
With a Shape object shp, set shp.Fill.ForeColor.SchemeColor or shp.Fill.ForeColor.RGB to an Ole color value. e.g. shp.Fill.ForeColor.SchemeColor = 13. It's more or less the same syntax as VBA. You can also get a shape object with ex.Shapes.get_Range("shpOne") once they've been assigned names.
Joel Goodwin
thanks a lot goodgai!