0

I'm trying to create a combobox and populate it with a list of all fonts available in the system. I had a look at this topic-->Fill ComboBox with List of available Fonts and I found the following code in C#:

     List<string> fonts = new List<string>();

        foreach (FontFamily font in System.Drawing.FontFamily.Families) 
         {        
           fonts.Add(font.Name); 
         }

I tried to convert it to something like this in C++/CLI:

List<string> fonts = gcnew List<string>();

             foreach (FontFamily font in System::Drawing::FontFamily::Families)
             {
                 fonts->Add(font->Name);
             }

But it didn't work. Can someone help me convert that C# code to C++/CLI?

Community
  • 1
  • 1
sparrow.
  • 101
  • 8

1 Answers1

0

Inspired by this site ,You may write like this:

list<string>* fonts = new list<string>();
System::Collections::IEnumerator^ myEnum = FontFamily::Families->GetEnumerator();

while (myEnum->MoveNext())
{
    FontFamily^ oneFontFamily = safe_cast<FontFamily^>(myEnum->Current);
    fonts->push_back(oneFontFamily->Name);
}

fonts here is a pointer, something does not exist in C#, be aware!

prehistoricpenguin
  • 6,130
  • 3
  • 25
  • 42