How to export form as an image (not during runtime) - vb.net

I'm using Visual Studio just to create GUIs for a project. There is no code, only the designs.
I need to convert these forms into images that I can paste into the report.
Is there a simple way to do this?
Thanks.
Edit: the only solution I have so far is to edit the project so that each window I want to export is the start up form, but I am going to have over 40 forms, so this will get tedious after awhile.

Create a new Class in your Projects, lets say Startup.vb, which looks something like this:
Friend Class Startup
<STAThread()> _
Public Shared Sub Main()
Application.Run(New Form1)
Application.Run(New Form2)
Application.Run(New Form3)
End Sub
End Class
In the Project Properties the general Tab, untick Enable application framework and choose Startup as new start-object.
Obviously you'd need to adjust your startup class to open all forms you wish to open. When running the application just press Alt+PrintScr to copy an image of just the selected Window/Form to the clipboard. Paste that back into the paint application of your choice. Microsoft Paint will do.

Using a screen capture program might be your best choice. Personally I recommend TechSmith SnagIt application. You can capture any selected region in the screen using this application.

If you right click on the form a select Lock Controls this will remove the resize handles you can then press PrtScn to take a copy.
Note: After applying Lock Controls it does still have a focus rectangle and lock symbol but these are outside the co-ordinates of the form so they could be cropped in MS Paint or similar?

Related

Control which form will load first in vb.net by coding

Is there a way to control which form will load first when the program starts in vb.net programmatically? Like a main method or something like that?
Yes, this is possible.
Add a public Main somewhere. (For example in a new class)
Public Shared Sub Main()
'Create and show your form here
End Sub
Then in the application settings, disable "Enable application framework" and select the Main method as the startup object.

Buttons change style at run time

I have a vb.net Windows Forms application using Visual Studio 2010. At design time my buttons look like this:
at run time they seem to revert to a Windows classic style:
It only happens for this project which I took over from a developer who left. I want them to look like they do at design time. I'm stumped. Any ideas?
If the app starts from a Sub Main rather than a main form (See Project -> Properties -> StartUp Object) it might be missing this:
Public Sub Main()
' probably missing:
Application.EnableVisualStyles()
Application.Run(New Form1)
End Sub
When starting from a Main sub, be sure that EnableVisualStyles() is invoked very early in the procedure before any UI Objects are created.
If it starts from a main form, go to the same Project properties and be sure that both Enable application framework and Enable XP Visual Styles are checked.
If it still doesnt work, turn on Show All Files in Solution Explorer and open Application.myApp under My Project. Make sure this setting is true:
<EnableVisualStyles>true</EnableVisualStyles>
This file/setting should be managed by VS, so if it is not being updated to match the IDE, you might have other issues.

How to set the class of a vb.NET control after it's been created already

I have a Windows Form with 7 Picture Boxes on it that are called PropButton1 through to PropButton7. I know they aren't buttons but I'm using them as buttons anyway (normal buttons aren't suitable for this purpose).
I want to add a custom "File Path" property to the Picture Boxes. To do this I've created a separate class that inherits the PictureBox class:
Public Class PropButton
Inherits PictureBox
Private SoundFilePath As String
Public Property SoundFile() As String
Get
Return SoundFilePath
End Get
Set(value As String)
SoundFilePath = value
End Set
End Property
End Class
I want to convert the original Picture Boxes from PictureBox to PropButton so I can read and write to things like PropButton1.SoundFilePath and I preferably want to do this without having to delete all of my Picture Boxes and start again. Is there a way to do this?
In Visual Studio look to the right in the Solution Explorer. It has a toolbar button to Show all files. Click it and you will see that you can expand the tree nodes for the forms and they contain three files. One that contains your source code, and another one called a Designer. The Designer file is automatically generated by Visual Studio and in most cases it should not be touched.
When you open the designer file you see all the initializations of the controls on your form and their declarations. Here you can easily change the declarations of your pictureboxes so that they are created as PropButtons instead.
Just be careful what you change here, because it can mess up the Visual Studio designer. But it is good to know what happens behind the scenes.
Look here first:
Change this...
...to this.
Yes, that is possible with the text editor. The Visual Basic IDE hides too much information, first thing you want to do is click the "Show All Files" icon in the Solution Explorer window. That adds a node next to your form in the same window, open it and double-click the Designer.vb file. Note the InitializeComponent() method and the declarations at the bottom of the file, you see the PictureBoxes being declared and initialized.
You can now simply Edit+Replace "System.Windows.Forms.PictureBox" with "PropButton".
Ensure you have a good backup before you do this.

VS2010 VB.NET Winforms select startup form programmatically

I'm really struggling to find out how to dynamically load a form when starting a VB.NET winforms application in VS2010.
Looking at existing answers such as this: Programmatically change the startup form on application launch?
Has not helped. I do not have a main method (that I can see) in my winforms project and when I go into the project properties I can only select a start-up form. But I have one of two forms to display on start-up depending on the user accessing the application.
I tried to set a loading form up which, in it's load event would call .Show() on the correct loading form after it had determined it and then the loading form would close itself down, but doing this led to both forms being closed.
Below are steps for VS2010 VB.NET Winforms select startup form programmatically.
1 : Go to My project from Solution Explorer
2 : Click on Application Tab--->Uncheck Enable application Framework
3 : Then Inside module create Sub like this
Public Sub Main()
MsgBox("called Main") 'This is testing
Login.Show() 'Set your start up form here
End Sub
4 : Again My Project--->Application Tab--->Startup Object--->Sub Main
5 : Thats it, It will give you message box and will show Login form.
Hope It will help you.
Thanks
Mahesh
Nevermind. I found in the properties a button to generate the MyApplication class in which I can access the startup event.
Another option is to use an MDI form. When it loads you can determine which child form to display.
Using Sub Main is the way I have done this forever but for some reason, MS has decided to make the norm, difficult. To use the Sub Main way, create a "Module" if you dont already have one. Put this code in there:
Sub Main()
Stop
End Sub
Now, in your project properties, assuming your are doing a standard WinForms application, on the "Application" tab, uncheck the "Enable Application Framework". This will allow you to see (and select) "Sub Main" in the "Startup Object" drop-down.

VB.net program with no UI

I'm making a VB.net program via a text file and I'm compiling it using vbc.exe via command line. I'm trying to get just a simple program to run in the background of my computer. Problem is, it displays the annoying console window. How do I get nothing to show? No form, no console?
Just use windows forms application don't load the form at all! Just go in project properties and uncheck enable application framework. Now, in the startup object dropdown, select "sub main". Add a module to the project and put a Public Sub Main() in it. You do all the stuff in main() and don't load form at all.
I think you need a form of some kind to keep the message loop going.
Maybe a NotifyIcon type program. It would keep it away from the task bar and desktop areas.
And then customize the NotifyIcon to "Only Show Notifications" from the "Customize" menu for your icon using Windows.
1) Add a module in your project, and create Sub Main
2) Write whatever you want in Sub Main,and MAKE SURE you end it with this statement:
Application.Run()
3) Open properties of your project and choose "Sub Main" as startup object
So , your application will have NO INTERFACE (NO FORM / NOT CONSOLE APPLICATION) and will run from Sub Main(), in addition it will NOT TERMINATE once all the code in Sub Main has executed.Your program will run like a NORMAL windows form application, and will only exit when you want.