我有一个表单,在拖动面板时应调整大小并重新定位。代码工作正常,但它闪烁。我认为问题是,C#立即调整大小并重新发布表单。经过研究,我发现了SuspendLayout()和ResumeLayout(),但看起来它只影响了内部内容。 DoubleBufferd = true和SetStyle(ControlStyles.OptimizedDoubleBuffer,true)也没有帮助。这是我在MouseMove EventHandler中的代码:
//_panMoverOffset is a point storing the start point
private void panMover_MouseMove(object sender, MouseEventArgs e)
{
if (_panMoverOffset != Point.Empty) // Indicates, if it should resize and repos
{
var offset = e.X - _panMoverOffset.X;
SuspendLayout(); // Should stop form from being redrawn
// Do resize and repos stuff
var newLocation = Location;
newLocation.X += offset;
Location = newLocation; // It resizes immediately (I checked it with break points)
Width -= offset; // This also
ResumeLayout(true); // Should force changes
}
}
这个想法是调整无边框形式的左侧。我在表单边缘使用了一个面板来指示鼠标移动。
有人知道,如何防止C#立即更新或如何以其他方式消除这些闪烁?