LoginSignup
0
0

More than 3 years have passed since last update.

WinFormsでリフレクション

Last updated at Posted at 2020-03-01

カルチャの変更

Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");

Assemblyの取得

var assembly = System.Reflection.Assembly.Load("TargetApp");

型の列挙

assembly.GetTypes()

FormとUserControl以外はじく

if(!(type.IsSubclassOf(typeof(Form)) || type.IsSubclassOf(typeof(UserControl)))) continue;

インスタンス化

var instance = Activator.CreateInstance(type);

コントール列挙

foreach (FieldInfo memberInfo in ti.DeclaredFields)
{
    var declareField = memberInfo.GetValue(instance);
}

Formキャプチャ

Bitmap bmp = new Bitmap(form.Width,form.Height);
form.DrawToBitmap(bmp, new Rectangle(0, 0 ,form.Width, form.Height));
bmp.Save(type.FullName + ".bmp");

UserControlをFormに追加してキャプチャ

var userControlForm = new Form();
userControlForm.ControlBox = false;
userControlForm.Controls.Add((UserControl)instance);
userControlForm.Show();
Bitmap bmpUserControl = new Bitmap(userControlForm.Width, userControlForm.Height);
userControlForm.DrawToBitmap(bmpUserControl, new Rectangle(0, 0, userControlForm.Width, userControlForm.Height));
bmpUserControl.Save(type.FullName + ".bmp");
userControlForm.Close();
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0