c# - Use DrawingBrush to create two Vertical Lines -
c# - Use DrawingBrush to create two Vertical Lines -
i trying create 50 x 50 square has half of rectangle white , other half black (the lines going vertically instead of horizontally). have next code, not filling rectangle expected. how create 50% white , 50% black?
system.windows.shapes.rectangle swatch = new system.windows.shapes.rectangle(); swatch.width = 50; swatch.height = 50; drawingbrush blackbrush = new drawingbrush(); geometrydrawing backgroundsquare = new geometrydrawing(system.windows.media.brushes.white,null,new rectanglegeometry(new rect(25, 0, 50, 50))); geometrygroup ggroup = new geometrygroup(); ggroup.children.add(new rectanglegeometry(new rect(25, 0, 100, 100))); geometrydrawing checkers = new geometrydrawing(new solidcolorbrush(colors.black), null, ggroup); drawinggroup checkersdrawinggroup = new drawinggroup(); checkersdrawinggroup.children.add(backgroundsquare); checkersdrawinggroup.children.add(checkers); blackbrush.drawing = checkersdrawinggroup; blackbrush.viewport = new rect(0, 0, 0.25, 0.25); blackbrush.tilemode = tilemode.tile; swatch.fill = blackbrush; sp_thumbnails.children.add(swatch);
its simple have 3 sections have 1 more geometrydrawing object within drawinggroup. can configure number of geometrydrawing there within drawinggroup below.
please see generic solution problem display horizontal sections per groupcount value.
public void createrectangle(int groupcount) { rectangle swatch = new system.windows.shapes.rectangle(); swatch.width = 50; swatch.height = 50; double groupsize = 100 / groupcount; drawingbrush blackbrush = new drawingbrush(); drawinggroup checkersdrawinggroup = new drawinggroup(); //considering 3 groupcount list<solidcolorbrush> brushes = new list<solidcolorbrush>() { brushes.black, brushes.white,brushes.red }; double location = 0; (int = 0; < groupcount; i++) { geometrydrawing drawing = new geometrydrawing(brushes[i] , null, new rectanglegeometry(new rect(0, location,groupsize,groupsize))); checkersdrawinggroup.children.add(drawing); location += groupsize; } blackbrush.drawing = checkersdrawinggroup; swatch.fill = blackbrush; brdrect.children.add(swatch); }
c# wpf
Comments
Post a Comment