ちらつきが非常に悪いWinformユーザーコントロールがあります。コントロールの機能は完璧に機能しています。ちらつきが本当にひどいです。ビットマップにすべての描画を行ってから、DrawImage
ビットマップを画面にコピーするだけなので、ちらつきの量に驚いています。ここに私が持っているものの抜粋があります:
private void ScrollPanel_Paint(object sender, PaintEventArgs e)
{
var c = (Calendar)Parent;
Bitmap bmp = c.RequestImage();
if (bmp == null)
return;
e.Graphics.DrawImage(bmp, new Rectangle(0, 0, ClientSize.Width, ClientSize.Height),
new Rectangle(0, _scrollOffset, ClientSize.Width, ClientSize.Height),
GraphicsUnit.Pixel);
_bmpSize = bmp.Height;
e.Graphics.Dispose();
bmp.Dispose();
}
private void ScrollPanel_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_mouseDown = true;
_oldMouseCoords = e.Location;
}
}
private void ScrollPanel_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
_mouseDown = false;
}
private void ScrollPanel_MouseMove(object sender, MouseEventArgs e)
{
if (_mouseDown && e.Location.Y < _oldMouseCoords.Y && _scrollOffset < _bmpSize - _scrollOffset - ClientSize.Height)
{
int offset = _oldMouseCoords.Y - e.Location.Y;
_scrollOffset += offset;
Refresh();
}
if (_mouseDown && e.Location.Y > _oldMouseCoords.Y && _scrollOffset > 0)
{
int offset = e.Location.Y - _oldMouseCoords.Y;
_scrollOffset -= offset;
Refresh();
}
_oldMouseCoords = e.Location;
}
マウスでドラッグすると、ビットマップがスクロールされるはずです。私が言ったように、機能はすべて機能しています。イベントからわかるようPaint
に、ビットマップを取得して画面に直接コピーするだけです。
どんな助けでも大歓迎です。