Hi, all
I must apologise if these questions had been asked before.
1)
Why Assembly.Load(" System.Windows. Forms") ?
2)
How can I set/get property of an object using reflection.
More specfically, how to acomplish the effect of
this.Text = "Hello World";
in the following program
Thank in advance,
=============== =============== =============== ===
using System;
using System.Reflecti on;
using System.IO;
public class Form1
{
static object sf;
public Form1()
{
//this.Text = "Hello World";
Assembly a1 =
Assembly.LoadFr om(@"C:\WINDOWS \Microsoft.NET\ Framework\v1.1. 4322\System.Win dows.Forms.dll" );
Type t = a1.GetType("Sys tem.Windows.For ms.Form");
sf= Activator.Creat eInstance (t);
// Type t1 = a1.GetType("Sys tem.Windows.For ms.Control");
// PropertyInfo prop= t1.GetProperty( "Text", new
Type[]{typeof(string) }); // kein Parameter
// object[] args = new object[]{"hello world" };
// object result = prop.SetValue(t , args,null); // kein Parameter
}
static void Main()
{
//System.Windows. Forms.Applicati on.Run(new Form1());
Form1 s= new Form1();
Assembly a1 =
Assembly.LoadFr om(@"C:\WINDOWS \Microsoft.NET\ Framework\v1.1. 4322\System.Win dows.Forms.dll" );
// Assembly a1 = Assembly.Load(" System.Windows. Forms");
Type t1 = a1.GetType("Sys tem.Windows.For ms.Form");
Type t2 = a1.GetType("Sys tem.Windows.For ms.Application" );
MethodInfo method = t2.GetMethod("R un", new Type[]{t1});
object result = method.Invoke(n ull, new object[]{sf});
}
}
I must apologise if these questions had been asked before.
1)
Why Assembly.Load(" System.Windows. Forms") ?
2)
How can I set/get property of an object using reflection.
More specfically, how to acomplish the effect of
this.Text = "Hello World";
in the following program
Thank in advance,
=============== =============== =============== ===
using System;
using System.Reflecti on;
using System.IO;
public class Form1
{
static object sf;
public Form1()
{
//this.Text = "Hello World";
Assembly a1 =
Assembly.LoadFr om(@"C:\WINDOWS \Microsoft.NET\ Framework\v1.1. 4322\System.Win dows.Forms.dll" );
Type t = a1.GetType("Sys tem.Windows.For ms.Form");
sf= Activator.Creat eInstance (t);
// Type t1 = a1.GetType("Sys tem.Windows.For ms.Control");
// PropertyInfo prop= t1.GetProperty( "Text", new
Type[]{typeof(string) }); // kein Parameter
// object[] args = new object[]{"hello world" };
// object result = prop.SetValue(t , args,null); // kein Parameter
}
static void Main()
{
//System.Windows. Forms.Applicati on.Run(new Form1());
Form1 s= new Form1();
Assembly a1 =
Assembly.LoadFr om(@"C:\WINDOWS \Microsoft.NET\ Framework\v1.1. 4322\System.Win dows.Forms.dll" );
// Assembly a1 = Assembly.Load(" System.Windows. Forms");
Type t1 = a1.GetType("Sys tem.Windows.For ms.Form");
Type t2 = a1.GetType("Sys tem.Windows.For ms.Application" );
MethodInfo method = t2.GetMethod("R un", new Type[]{t1});
object result = method.Invoke(n ull, new object[]{sf});
}
}
Comment