c# - how to use drawline function only once during form load? -
i using drawline function drawing horizontal , vertical lines making x-y coordinate graph.the problem in blinking of backgroundgraph everytime draw other shape such rectangle , ellipse. everytime write new shape object drawline function executes , reloads blinking effect till stop drawing.how resolve problem?i using drawline function backgroundgraph , not using line shape in application.i have tried drawline in formload doesn't work parameters formload , drawline mismatches.so how can make graph constant(calling once)?
here code:
private void draw(graphics e, point mold, point mcur, int mshape, float mwidth, color mcolor) { int numofcells = 100; int cellsize = 25; (int = 0; < numofcells; i++) { pen pn = new pen(color.lightslategray, ((mwidth - 1) / 25)); // vertical e.drawline(pn, * cellsize, 0, * cellsize, numofcells * cellsize); // horizontal e.drawline(pn, 0, * cellsize, numofcells * cellsize, * cellsize); } pen p = new pen(mcolor, mwidth); switch (mshape) { case 0: e.drawrectangle(p, rec(mold, mcur)); break; case 1: e.drawellipse(p, rec(mold, mcur)); break; } } private rectangle rec(point p1, point p2) { rectangle = new rectangle(); a.x = (p1.x > p2.x ? p2.x : p1.x); a.y = (p1.y > p2.y ? p2.y : p1.y); a.width = math.abs(p1.x - p2.x); a.height = math.abs(p1.y - p2.y); return a; }
you can use off-screen buffering or double buffering.
- create memory object
- perform drawing in memory graphics object
- once done in memory, transfer whole content screen
read below code project article: http://www.codeproject.com/articles/12870/don-t-flicker-double-buffer
Comments
Post a Comment