Filling a shape of visio with color in c# -
hi creating shapes of visio2013 using c# .now need fill shape colors using c# tried below codes nothing makes sense :( :(
visio.cell cqellname; cqellname = shape.get_cellssrc( (short)visio.vissectionindices.vissectionobject, (short)visio.visrowindices.visrowfill, (short)visio.viscellindices.visfillbkgnd); cqellname.formulau = "rgb(255,0,0)";
above code throws error cell guarded.
shape.get_cellssrc((short)visio.vissectionindices.vissectionobject, (short)visio.visrowindices.visrowfill, (short)visio.viscellindices.visfillbkgnd).formulaforceu = "rgb(" + r + "," + g + "," + b + ")";
tried above, doesn't throw exceptions nothing changed in shape.
i tried solution from stackoverflow , not working
i can able see value assigned me in shapesheet fillforegnd , fillbkgnd , shape not filling color gave .
can 1 please tell me how this..??
as mentioned in answer above (which have marked not useful) targeting wrong shape.
now you've editted question include more details it's clear shape you're dealing with.
the shape you're targeting appears "collapsed sub-process" "bpmn basic shapes" stencil. group shape , top level has no geometry, changing color, you're doing in question, has no visual change. solve need find sub-shape used show background. happens in specific master, sub-shape contains fill need target has index 1 greater parent, can use in code. shape lacks other clear features (such user cell) make better candidate please note method particular shape.
given appear doing fair bit of work stencil, approach create copy of stencil , make modifications masters make kind of interaction little easier, hope in meantime following code answers question.
please mark answered if that's case.
public void oncheckfillbpmn() { color fillcolor = color.fromargb(1, 255, 0, 0); collapsedsubprocessfill(this.application.activewindow.selection.primaryitem, fillcolor); } private void collapsedsubprocessfill(visio.shape vshpin, color fillcolor) { if (vshpin != null && vshpin.master != null && vshpin.master.nameu.startswith("collapsed sub-process")) { //the sub-shape provides fill colour in //the 'collapsed sub-process' master first index //after group shape. //if want use different method locate //correct sub-shape here. var targetsubshpid = vshpin.id + 1; var targetshp = trygetshapeincollection(vshpin.shapes, targetsubshpid); if (targetshp != null) { var targetcell = targetshp.get_cellssrc( (short)visio.vissectionindices.vissectionobject, (short)visio.visrowindices.visrowfill, (short)visio.viscellindices.visfillforegnd); targetcell.formulau = "rgb(" + fillcolor.r + ',' + fillcolor.g + ',' + fillcolor.b + ')'; } } } private visio.shape trygetshapeincollection(visio.shapes vshps, int shpid) { try { if (vshps != null) { var targetshp = vshps.itemfromid[shpid]; return targetshp; } } catch (system.runtime.interopservices.comexception ex) { if (ex.errorcode == -2032465756) //invalid sheet identifier { return null; } } return null; }
Comments
Post a Comment