Код: Выделить всё
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; this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.UpdateStyles(); } protected override void OnScroll(ScrollEventArgs se) { // Only invalidate if necessary if (se.NewValue != se.OldValue) { base.OnScroll(se); this.Invalidate(); // Optionally restrict this call } } }
private async void BtnSearchItem_Click(object sender, EventArgs e) { FLOWITEM.Controls.Clear(); // Clear existing items FLOWITEM.FlowDirection = FlowDirection.TopDown; FLOWITEM.AutoScroll = true; // Populate item list for (int i = 0; i < 300; i++) { await Task.Delay(1); var item = new Uis.CONTROLS.Item(); FLOWITEM.Controls.Add(item); // Add items directly to the FlowLayoutPanel } SetDoubleBuffer(FLOWITEM, true); } static void SetDoubleBuffer(Control ctl, boolDoubleBuffer) { 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); } }
public Main_Page() { InitializeComponent(); SetDoubleBuffer(FLOWITEM, true); }
Будем благодарны за любые рекомендации!
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-bufferin