I have used every suggested methods from this following topic but no luck.
When I debug, it always skip after the "If" condition line without checking. I don't know why.
For example:
string fontName = "Consolas";
float fontSize = 12;
using (Font fontTester = new Font(
fontName,
fontSize,
FontStyle.Regular,
GraphicsUnit.Pixel))
{
if (fontTester.Name == fontName) <<<<< [1]
{
// Font exists
}
else
{
// Font doesn't exist
}
} <<<<< [2]
After I marked and pressed F10/F11 on [1] line, it always go to [2] without checking.
This is my actual code:
private static void Main(string[] args)
{
if (args.Length == 0)
{
args = new string[] { AppDomain.CurrentDomain.BaseDirectory + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".txt" };
}
if (args.Length > 0)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string fontName = "Free 3 of 9 Extended";
float fontSize = 12;
using (Font fontTester = new Font(
fontName,
fontSize,
FontStyle.Regular,
GraphicsUnit.Pixel))
{
if (fontTester.Name == fontName)
{
// Font exists
}
else
{
// Font doesn't exist
}
}
Application.Run(new MenuForm());
}
}
UPDATED:
I checked my project properties again and unchecked "Optimize Code" in "Build" tab then it's worked.