Код: Выделить всё
I'm working on a WinForms application with a FlowLayoutPanel that contains multiple custom controls. When I scroll through, the controls noticeably flicker, even though I’ve enabled double buffering. My goal is to achieve a smooth scrolling experience without the visible flicker.

ПОЛЬЗОВАТЕЛЬСКАЯ ПАНЕЛЬ ПОТОКА С БУФЕРОМ
Код: Выделить всё
internal class DrawFLP : FlowLayoutPanel
{
public DrawFLP()
{
this.DoubleBuffered = true;
//SetStyle(ControlStyles.OptimizedDoubleBuffer,
true);
}
protected override void OnScroll(ScrollEventArgs se)
{
this.Invalidate();
base.OnScroll(se);
}
}
Код: Выделить всё
private async void BtnSearchItem_Click(object sender, EventArgs e)
{
// Enable double buffering on FLOWITEM
SetDoubleBuffer(FLOWITEM, true);
// Clear existing items and configure FLOWITEM properties
FLOWITEM.Controls.Clear();
FLOWITEM.FlowDirection = FlowDirection.TopDown;
FLOWITEM.AutoScroll = true;
// Populate the item list asynchronously
for (int i = 0; i < 300; i++)
{
await Task.Delay(1);
var item = new Uis.CONTROLS.Item();
FLOWITEM.Controls.Add(item);
}
}
Код: Выделить всё
static void SetDoubleBuffer(Control ctl, bool DoubleBuffer)
{
try
{
typeof(Control).InvokeMember(
"DoubleBuffered",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.SetProperty,
null,
ctl,
new object[] { DoubleBuffer }
);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Будем благодарны за любые рекомендации!
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-bufferin