c# - Fix DataGridView scroll blitting / jerkyness -
in windows forms, created custom row headers datagridview
draws faces of game characters. however, noticed when scrolling datagridview
, windows seems blit existing rows on not-yet-drawn ones, creating noticeable , annoying jerkiness.
this how looks artificially slowed down when scrolling , down (it fast in reality, jerkiness still noticable - gif has been slowed down show mean blitting):
this seems happen default datagridviewrowheadercell
, other cells (which didn't supply custom drawing code, notice numbers not updating aswell in gif above), not noticable due them not having images / faces (quickly recognizable human) , alternating row colors.
so looks datagridview has these problems in general, become perceivable images. there way prevent datagridview
blitting contents or windows causing it, chances low prevent doing so?
the drawing double buffered. tried wm_setredraw
, didn't find fitting "prescroll" , "postscroll" events try use it.
for reference, current row header drawing code, in class inheriting datagridviewrowheadercell
. computes area in draw image , text. however, said, _the specific code unimportant_, default implementation suffers the blitting issue.
protected override void paint(graphics graphics, rectangle clipbounds, rectangle cellbounds, int rowindex, datagridviewelementstates datagridviewelementstate, object value, object formattedvalue, string errortext, datagridviewcellstyle cellstyle, datagridviewadvancedborderstyle advancedborderstyle, datagridviewpaintparts paintparts) { // draw background. base.paint(/*base parameters cut brevity*/); // draw image. rectangle imagebounds; if (_image == null) { imagebounds = new rectangle( cellbounds.x + (cellbounds.width / 2), cellbounds.y + cellstyle.padding.top, 0, 0); } else { // draw image in size available in header , respect dpi. size imagesize = new size(_image.width * _dpiscale, _image.height * _dpiscale); imagebounds = new rectangle( cellbounds.x + (cellbounds.width / 2) - (imagesize.width / 4), cellbounds.y + cellstyle.padding.top, imagesize.width / 2, imagesize.height / 2); // cached, resized image in required size. graphics.drawimageunscaled( program.r.getsizedbitmap(_image, imagebounds.size), imagebounds); } // draw text. rectangle textbounds = new rectangle( cellbounds.x, imagebounds.bottom, cellbounds.width, cellbounds.bottom - imagebounds.bottom); textrenderer.drawtext(graphics, _text, cellstyle.font, textbounds, cellstyle.forecolor, cellstyle.backcolor, textformatflags.horizontalcenter | textformatflags.verticalcenter); }
Comments
Post a Comment