• Advertisement
Sign in to follow this  

[.net] Displaying lots of text nicely - performance concerns and questions

This topic is 3388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm currently maintaining several database applications at work, which do anything from displaying a list of telephone numbers, to displaying detailed customer order information based on who booked this week etc. Since multiple users are be running this software (usually from a Terminal Services session) I want to keep CPU and Memory costs down to an absolute minimum. The main concern for our users is presentation; the information has to be displayed neatly and quickly in response to text queries, similar to how a search engine works, allowing users to find exactly what they need instantly. I have been able to please our users in this regard but as my forms get increasingly clever, I have noticed resource usage creep up. My database queries peform quickly, and they're loaded into Data.Datatables as fast as I could possibly wish for but I have noticed that Windows forms can sometimes be a bit slow refreshing, particularly with forms that rely heavily on the Anchor and the Dock properties of controls. They don't refresh pleasingly, they get part-drawn for a brief moment. I have tried setting the form to double-buffered and toggling between .Suspendlayout and .Resumelayout in the code, but it's still slower than I think it should be. I use the datagridview as much as possible because it seems fast and efficient enough, however not all information looks great presented in a grid, so I have to start from scratch with the basic controls. MY QUESTIONS THEREFORE ARE: 1) In terms of cpu performance and memory, which of the following controls are the quickest to draw/refresh when displayed en masse, and are there any properties which can slow them down - such as border style or autosize? Labels ? TextBoxes ? Panels ? (I rely on these a lot, especially for quickly grouping controls) Flowcontrolpanels? Tablelayoutpanels? 2) Is there a lot of overhead associated with creating controls at run-time? It's easier for me personally to manipulate them this way, but would drawing most of them onto the designer beforehand help matters? 3) Say I create a custom control which has a panel, textbox, 3 labels and a button - and this is displayed 50 times in a tabular format... this is going to be quite busy... are there any caveats for forms like this? Aside from that, any advice or criticsm would be most welcome.

Share this post


Link to post
Share on other sites
Advertisement
1) I'd roll my own simple label control wrapping some simple gdi text rendering calls. Moreover, some objects such as the control font can be shared across all label instances, thus limiting memory usage.

Consider that GC happens upon allocation, so if you know you have loads of text controls you might want to pool those and use them accordingly.

When adding many controls at once to a panel, for instance (reflector can confirm your feeling of "lightweightness"), make sure to call SuspendLayout and ResumeLayout.

SuspendLayout

2) I'm not sure what you mean by drawing them beforehand in the designer. Controls are getting repainted at runtime when necessary, so I'm not sure it'd help.

3) It could get busy. A solution could be another custom control which shows a static textbox whenever the user needs to edit something. Since the user can edit one textbox at once in most cases, it could suit you fine. For the buttons, again, a simpler control can help you out. The ControlPaint class has what you need to paint standard graphical elements such as 3d borders and so on.


hth

Share this post


Link to post
Share on other sites
This is probably already the case, but are you calling Application.SetCompatibleTextRenderingDefault(false) at startup? This will make controls use GDI for text rendering instead of GDI+ which should result in an increase in speed in text rendering.

Share this post


Link to post
Share on other sites
" I'd roll my own simple label control wrapping some simple gdi text rendering calls. Moreover, some objects such as the control font can be shared across all label instances, thus limiting memory usage. "


Wow, interesting idea. I will definately experiment with this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement