|
-
Jun 18th, 2013, 04:40 AM
#1
Thread Starter
Frenzied Member
Print screen shot of every form in a folder
I want to create a document (probably MS Word) containing screen shots of every form in each of my company's projects.
There is no one .sln that contains all the .proj files. However, the .proj files are all in one directory structure.
We're using VS2012, so the macro functionality from previous versions is not available to us.
Ideally I would like each screenshot to be associated with, say, the filename of the .frm so they can be easily identified by reviewers.
I realise that the screen shots will probably be how the form looks in the IDE, rather than how it looks at runtime. This is ok.
We are using a mixture of VB.NET and C# forms.
Does any one have any ideas that might help me?
This world is not my home. I'm just passing through.
-
Jun 18th, 2013, 08:47 AM
#2
Re: Print screen shot of every form in a folder
Take a look at this thread. What that does is store files with their icons in a listview. You could filter the icons by just the extension(s) that you need. Even more so you could start the process, by handling the listview's double-click event and calling Process.Start(<file name>). I wager it's much easier to do that than trying to create a word document of some screenshots.
-
Jun 18th, 2013, 08:59 AM
#3
Re: Print screen shot of every form in a folder
You can write some code to processes the assembly looking for any objects that inherit from the Form type, and then create an instance of the form and attempt to display it. This may cause issues if a form is dependant on data or a framework, like a docking system. Possibly you can create the interface and show it, without running the standard events (I've never tried), such as calling the InitializeComponent, method directly. Could at least be a start!
-
Jun 18th, 2013, 09:02 AM
#4
Re: Print screen shot of every form in a folder
For example, here I process all types looking for ones that use my own Interface (I've changed the name to a string here). I look in the .exe file, and also in sub-assemblies, but you may not need that.
Code:
'Ask the entry assembly (main .exe program) for its types
Dim fullTypeList() As Type = System.Reflection.Assembly.GetEntryAssembly.GetTypes
For Each typTest As Type In fullTypeList
If Not typTest.GetInterface("MyInterface)) Is Nothing Then
End If
Next
'Now ask for each assembly loaded by the entry assembly, and then in turn process each one of those
Dim subAssemList() As AssemblyName = System.Reflection.Assembly.GetEntryAssembly.GetReferencedAssemblies
For Each subAssem As AssemblyName In subAssemList
Dim partTypeList() As Type = System.Reflection.Assembly.Load(subAssem).GetTypes
For Each typTest As Type In partTypeList
If Not typTest.GetInterface("MyInterface)) Is Nothing Then
End If
Next
Next
Last edited by Grimfort; Jun 18th, 2013 at 09:06 AM.
-
Jun 18th, 2013, 09:38 AM
#5
Thread Starter
Frenzied Member
Re: Print screen shot of every form in a folder
 Originally Posted by Grimfort
You can write some code to processes the assembly looking for any objects that inherit from the Form type, and then create an instance of the form and attempt to display it. This may cause issues if a form is dependant on data or a framework, like a docking system. Possibly you can create the interface and show it, without running the standard events (I've never tried), such as calling the InitializeComponent, method directly. Could at least be a start!
Thanks, Grimfort.
I've made a start using that approach. As you predicted, I'm having lots of trouble with forms that area dependant on data being passed into their constructors. I've used some more reflection to mock the necessary constructor parameters, which works in some cases.
Here's the code I'm using to capture a screenshot and write it to a bitmap on disk. Works nicely where it works...
Code:
frm = DirectCast(Activator.CreateInstance(formType, args), Form)
If frm IsNot Nothing Then
frm.Show()
frm.Top = 0
frm.Left = 0
frm.Refresh()
Application.DoEvents()
Dim bmp As New System.Drawing.Bitmap(frm.Width, frm.Height)
frm.DrawToBitmap(bmp, frm.Bounds)
Application.DoEvents()
bmp.Save("C:\GenScreenShot\" & formType.Name & ".bmp")
frm.Close()
frm = Nothing
End If
This world is not my home. I'm just passing through.
-
Jun 18th, 2013, 09:41 AM
#6
Thread Starter
Frenzied Member
Re: Print screen shot of every form in a folder
 Originally Posted by dday9
Take a look at this thread. What that does is store files with their icons in a listview. You could filter the icons by just the extension(s) that you need. Even more so you could start the process, by handling the listview's double-click event and calling Process.Start(<file name>). I wager it's much easier to do that than trying to create a word document of some screenshots.
dday9, thank you for the suggestion. It looks like that thread is more to do with executable files rather than individual WinForms. I'm beginning to thing (see my reply to Grimfort) that I've taken on rather too much of a job here! I'm getting some results out though, so it's a start.
This world is not my home. I'm just passing through.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|