Way to speed this up? Adding custom UserControl to Controls Collection
Using C# while writing a Windows Form application.
I have a "main" UserControl which I intend to use for showing a collection of other UserControls.
Right now I am keeping it simple and just hard-coding the adding of the usercontrols to the "main" usercontrol.
I added 300 of the controls and they seemed to add okay.
But when I scroll the window for the "main" control there is a bunch of ... lag? ... as i scroll. The mouse pointer begins to move in slow motion. My guess is that it is related to the "main" control re-drawing itself. Once that process finishes, the mouse speed goes back to normal.
Tips? Tricks?
I cannot believe that I am taxing the operating system THAT MUCH with my simple controls. We're talking about bunch of textboxes, for crying out loud.
DataGridViews can have a lot more data and they scroll with no lag. So what am i doing that is so different?
Frustrated that I am having to put up with this! C# and Window Forms development has been around for a while.
code for adding my user controls to the "MAIN" control:
using System.Data;using System.Windows.Forms;namespace DocumentController{ public partial class InMemoryGrid : UserControl { public InMemoryGrid() { InitializeComponent(); InMemoryRow imr; InMemoryCell imc; UniversalDataClass udc; int top = 0; for(int i = 0; i < 300; i++) { imr = new InMemoryRow(); for(int j = 0; j < 10; j++) { imc = new InMemoryCell(); udc = new UniversalDataClass() { RawObject = "Hello" }; imr.AddInMemoryControl(imc); imr.Top = top; imc.ShowOnly(WhichControl.textbox); imc.SetValue(WhichControl.textbox, udc); } Controls.Add(imr); top += 50; } } public GlobalSpreadsheetRAWDataHelper gs { get; set; } }}
First see if enabling double buffering on your control has any benefit:
public partial class InMemoryGrid : UserControl { public InMemoryGrid() { InitializeComponent(); this.DoubleBuffered = true; // ... rest of your code ... } }
That was a good idea and I was excited to see if that was the case, but no, it still lags when I scroll, meaning, the mouse pointer slows to a crawl. I have to wait for *whatever it is* to finish processing, then I can use the mouse as normal.
Do you offer paid services? For example, through Experts Exchange "Tech Help"?
To give you some context: I am working as a lone contractor. This piece of the project is due tomorrow. If I meet with the company that is contracting with me and this is not finished ... I may be finished... : (
Open in new window