c# - How to draw rectangles consecutively in sth like a loop in Winform -
c# - How to draw rectangles consecutively in sth like a loop in Winform -
i need draw rectangles in winform image:
i should more clear. want accomplish scenario: let's there text in form "abcdefg" when user clicks b letter want add together background rectangle color (highlight) letter , successive 3 letters (in case, want highlight bcd).
in method tried this:
for (int = 0; < 5; i++) { letterarea = new rectangle(rectstartx, rectstarty, (int)math.ceiling(charsize.width), (int)math.ceiling(charsize.height)); rectstartx += (int)math.ceiling(charsize.width); } i phone call invalidate() @ end of method. in onpaintbackground have these lines:
rectangle rectcontent = vsr.getbackgroundcontentrectangle(e.graphics, this.clientrectangle); e.graphics.fillrectangle(new solidbrush(color.red), letterarea); where letterarea class field. read in question calling invalidate() in loop doesn't guarantee calling of onpaintbackground. not interested in calculating coordinates, instead, interested in method must draw rectangles , phone call invalidate() , efficient solution? thanks, in advance.
you should draw rectangles in onpaint method rather in onpaintbackground.
also note calling invalidate() doesn't not forcefulness synchronous paint. forcefulness synchronous paint, phone call update() after calling invalidate() or utilize refresh() doing same invalidate + update (but affects kid controls too). see msdn reference.
c# winforms user-interface drawing rectangles
Comments
Post a Comment