Solved

Populating listbox with Font Families is slowing down my form

Posted on 2012-03-22
3
242 Views
Last Modified: 2012-06-21
In my form load I have code that populates a dropdownmenuitem with font families.  It slows down my form loading just a tad.  Is there a way to speed that up?
//POPULATE FONT NAMES
            FontFamily[] ffArray = FontFamily.Families;
            foreach (FontFamily ff in ffArray)
            {
                if (ff.IsStyleAvailable(FontStyle.Regular))
                {
                    toolStripDropDownButton1.DropDownItems.Add(ff.Name);
                 }
0
Comment
Question by:pdering
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 245 total points
ID: 37755888
eager load it in a static List<FontFamily> at form load time like this:-

private static List<FontFamily> lstFonts;
public void Form_Load(object sender, EventArgs args)
{
lstFonts=LoadFonts();
}

private IList<FontFamily> LoadFonts()
{
return FontFamily.Families.Where(f=>f.IsStyleAvailable(FontStyle.Regular)).ToList();
}
0
 

Author Comment

by:pdering
ID: 37755973
what am i doing wrong?...

lstFonts = LoadFonts().ToList();
toolStripDropDownButton1.DropDownItems = lstFonts;
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37758544
Try this:-

        private void Form1_Load(object sender, EventArgs e)
        {
            var fonts = LoadFonts();
            fonts.ForEach(f => toolStripDropDownButton1.DropDownItems.Add(f.Name));
        }

        private static List<FontFamily> LoadFonts()
        {
            return FontFamily.Families.Where(f => f.IsStyleAvailable(FontStyle.Regular)).ToList();
        }

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question