//C#
Type fontType = typeof(Font);
//MC
Type^ t = Font::typeid;
//C#:
typeof(Font).InvokeMember("fieldName", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, fontInstanceToModify, new Object[] { /*Value to assign*/ });
//MC :
Font::typeid->InvokeMember(L"fieldName", BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::SetField, nullptr, fontInstanceToModify, gcnew cli::array<Object^>^ { /*Value to assign*/ });
// C#:
typeof(Font).InvokeMember("fontSize", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, fontInstanceToModify, new Object[] { 16f });
// MCPP:
Font::typeid->InvokeMember(L"fontSize", BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::SetField, nullptr, fontInstanceToModify, gcnew cli::array<Object^>^ { 16.0f });
// C#:
typeof(Font).InvokeMember("SetFontFamily", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, fontInstanceToModify, new Object[] { yourNewFontFamily });
// MC :
Font::typeid->InvokeMember(L"SetFontFamily", BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::InvokeMethod, nullptr, fontInstanceToModify, gcnew cli::array<Object^>^ { yourNewFontFamily });
// C#
typeof(Font).InvokeMember("CreateNativeFont", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, fontInstanceToModify, null);
// MC :
Font::typeid->InvokeMember(L"CreateNativeFont", BindingFlags::NonPublic | BindingFlags::Instance | BindingFlags::InvokeMethod, nullptr, fontInstanceToModify, nullptr);
public static void SetFontFamily(this Font myFont, FontFamily myFamily
{
typeof(Font).InvokeMember("SetFontFamily", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null,
myFont, new Object[] { myFamily });
typeof(Font).InvokeMember("CreateNativeFont", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null,
myFont, null);
}
public static void SetSize(this Font myFont, Single mySize)
{
typeof(Font).InvokeMember("fontSize", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, myFont,
new Object[] { mySize });
}
// Returns false if style wasn't supported
public static Boolean SetFontStyle(this Font myFont, FontStyle myStyle)
{
if(myFont.FontFamily.IsStyleSupported(myStyle))
{
typeof(Font).InvokeMember("fontSize", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, myFont,
new Object[] { mySize });
return true;
}
return false;
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Commented: