Question How to Get and Set External Application Form Property Using Reflection

Krishnaa

Member
Joined
Mar 23, 2014
Messages
7
Programming Experience
Beginner
Hi,

As we all know, using reflection, we can get access to the types of any external application as well as we can set the value of Fields too at runtime. I am trying to change the property of Winform application. I simply want to replace the Winform text using Reflection. Can anyone provide me solution for this problem?
 
Just because Reflection can give you information about the types contained in an assembly, you can't automatically access objects in a running application and manipulate them. That would akin to your being able to control every car because you know how a car works. If you want to change the text on a window of a running application then you would use the Windows API, specifically FindWindow to get the handle of the appropriate window and then SendMessage to send the WM_SETTEXT message to that window. That is not an uncommon combination so you should be able to find plenty of examples online.
 
Hi,

I am not talking about running assembly. I want to execute the assembly after making changes. So far I am able to change the static fields in the program before executing the main function using FieldInfo class. The only problem is, I am not able to change the property using PropertyInfo.
 
I am not able to change the property using PropertyInfo.

That's because it's an instance member and you have to have an instance in order to invoke an instance member. The application would have to be running and an object created in order to set an instance property and then it would only affect that instance and not any other instance of that type.
 
Thanks.

I created the instance, but I am getting error:

"SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application."

Any idea how to fix this?
 
Back
Top Bottom