How do I convert "byte gdicharset" to script / language name?

The FontDialog class in C # has an "AllowScriptChange" property that allows the user to select a script (Western, Hebrew, Arabic, Turkish, etc.). When enabled, the drop-down box provides all of these options and everything else is available depending on the selected font.

If the dialog is successful, the selected font has a GdiCharSet value, set to a value between 0 and 255.177 is Hebrew, 161 is Greek, and so on. Is there a function that will convert from value to string? I can write a switch statement, but I would like to do it right.

This is an incomplete list: http://msdn.microsoft.com/en-us/library/cc194829.aspx

Edit . A function that will convert from a CharSet to a codepage will also work because I think it should be easy to get the name of the codepage.

0


a source to share


1 answer


If you don't want to use a switch, how do you use rename? Sort of:

public enum CharSet : byte
{
        ANSI_CHARSET = 0,
        DEFAULT_CHARSET = 1,
        SYMBOL_CHARSET = 2,
        SHIFTJIS_CHARSET = 128,
        HANGEUL_CHARSET = 129,
        HANGUL_CHARSET = 129,
        GB2312_CHARSET = 134,
        CHINESEBIG5_CHARSET = 136,
        OEM_CHARSET = 255,
        JOHAB_CHARSET = 130,
        HEBREW_CHARSET = 177,
        ARABIC_CHARSET = 178,
        GREEK_CHARSET = 161,
        TURKISH_CHARSET = 162,
        VIETNAMESE_CHARSET = 163,
        THAI_CHARSET = 222,
        EASTEUROPE_CHARSET = 238,
        RUSSIAN_CHARSET = 204
    }

      

And you can customize the extension method if you are using .NET 3.5

public static class GdiCharHelper
{
    public static string ToGdiName(this byte GdiCharSet)
    {
            return Enum.GetName(typeof(CharSet), GdiCharSet);
    }
}

      

So, you can use it in your code like this:



string name = Font.GdiCharSet.ToGdiName();

      

EDIT: Now that I think about it, you should probably change the return value of the Extension method to be an enum, so:

return (CharSet)GdiCharSet;

      

So you can also compare:

If (Font.GdiCharSet.ToCharSet() == CharSet.ANSI_CHARSET) {...}

      

+5


a source







All Articles