I want to create automated screenshots of my WinForm-application. So e.g. I have a Form containing a TabControl and some Buttons. Then in the code I want to iterate through the Forms children, get their position by their Location-property and highlight them in the screenshot. In the example I'd have the TabControl, get its active page, screenshot the complete application and draw a rectangle around the page.
This could totally be done by adding a custom "Screenshot"-UserControl, but I'd like to separate this from the rest of the application, like having a programm that spawns the actual Form and then iterates through its children.
My current approaches so far:
- Using the managed win-api as a wrapper for PInvoke to iterate through the Form's handles
- Failed, because I couldn't determine, what type of Control I got (I used the ClassName-property)
- Using a custom AppDomain to spawn the application
I think the AppDomain-thing is the way to go, but I can't seem to find a way of grabbing an instanciated object from the custom domain. The AppDomain.CreateInstanceAndUnwrap(string name, string type)
creates new instances, so this won't help me I guess.
AppDomain d = AppDomain.CreateDomain("CaptureDomain");
domain.ExecuteAssembly(path);
object[] o = domain.GetObjects(); // <-- like this
foreach (object k in o)
{
Console.WriteLine(o.GetType().Name);
if (o is System.Windows.Forms.Form)
{
//iterate through children
}
}
Question
How can I make automated screenshots of my application?