Jump to content
  • Advertisement
Sign in to follow this  

[.net] Updating multiple Windows.Forms.Labels very slow

This topic is 3937 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

Hi there, As part of a game when I hover the mouse over a unit I show that units stats. To display the stats I alter the text of one label per attribute. The problem is this is really slowing my programme down when I am doing other graphical stuff at the same time as updating the stats. Below is an example.
unit card
In the code below all the updated items are labels apart from the last which is a textbox.
hoverCp.Text = hoveringUnit.Completions.ToString();
hoverTd.Text = hoveringUnit.Touchdowns.ToString();
hoverIt.Text = hoveringUnit.Interceptions.ToString();
hoverCs.Text = hoveringUnit.Casualties.ToString();
hoverVp.Text = hoveringUnit.MostValuablePlayer.ToString();
hoverSp.Text = hoveringUnit.Spp.ToString();
hoverName.Text = hoveringUnit.Name;

hoverMove.Text = hoveringUnit.Ma.ToString();
hoverStrength.Text = hoveringUnit.St.ToString();
hoverAgility.Text = hoveringUnit.Ag.ToString();
hoverArmour.Text = hoveringUnit.Av.ToString();

hoverSkills.Text = null;
foreach (string skill in hoveringUnit.SkillNames)
	hoverSkills.AppendText(string.Format("{1}{0}", Environment.NewLine, skill));
I'm not sure why simply updating text should take so, comparatively, long. If needed the full game can be found here including graphics, 3.9MB. Many thanks, John

Share this post

Link to post
Share on other sites
Updating a label isn't a slow operation, but updating many of them frequently can be, because there's more machinery involved than just setting some text (validation, events, book keeping, and so on). There may be other problems beyond that snippet of code as well.

The thing is, using labels for this purpose isn't ideal. They consume signifigantly more resources (being controls) than a simple text string would, and simply drawing the strings directly on to your render surface is probably more ideal.

Share this post

Link to post
Share on other sites
I was thinking about drawing them but using labels seemed more simple to update and layout. I'll update it to draw the text instead.


Share this post

Link to post
Share on other sites
One problem may be the refresh events of the form and labels.

When you are updating a lot of controls (GDI), tell the form and controls to not redraw until you are done. I think (although I could be wrong) that you can do this with the Layout stuff...

lblValue.Text = "Foo..."

Try it and see. There may be another property similar to it.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!