Showing form 2 before form 1 - vb.net

I have this VB.NET program that I wrote in Windows Visual Studio 2010 and there are two forms. The form1 will go first before form2 but now I changed my mind and I want form2 to load first when I open my program before form1. I have tried a lot of troubleshooting but no luck form1 is still loading first.

Double click on My Project in Solution Explorer. There you can set the Startup form to form2.

It sounds as if you have a straightforward windows forms project that does not have a sub main procedure (you should read up about sub main procedures as with that you could follow the advice in the in the comment below your question).
For your problem you need to click on 'My Project' in the solution explorer and then open up (if it doesn't open by default) the application tab. There are three drop down controls on the left hand side of the tab the last of which is 'Startup Object'. Under this you will find 'Form2'. Select that and your application will start with form 2 rather than form 1.

Go to the project menu and click " Properties" (the bottom option). In the tab that opens, change the drop down list labelled "Startup Form" to whichever form you want to show first.
Hope this helps!

The following steps may help out:
Click on form1, go to its Topmost property and set it to false.
Click on form2, go to its Topmost property and set it to true.
Double click on form1 and write the following code:
me.hide()
form2.show()
Double click on form2 and write the following code:
me.show()
form1.hide()
I have tried and it worked.

Please navigate on solution Explorer and click program.cs then change Application.Run(new nameoftheformyouwanttostartwith());
on where its written name of the for you want to start it then enter then name

Related

Microsoft Access can't open a form from inside another form with doCmd.OpenForm

I'm completely new to MS Access but not to databases. I have a form that is meant to open another form through a button and users are to add records to a target table through said form. The main menu fails to open my secondary form saying "recordset is not updatable". The table that is to receive the records is editable and I can go into it and manually add records so this doesn't seem to be the problem. If I click out of the error through the error handler menu I'm taken to the form that I expected to open, but it is read only-- I can't see it's properties sheet, design view, or even change the view at all. I looked at the VBA code on the main menu and it does use doCmd.OpenForm "myForm", , , , , ,"New"
Any pointers would be really appreciated.
Right click your form and click design view. Add a button, click Cancel and name the button appropriately. Than, right-click the button and click Build Event > Code Builder > OK. Copy/paste the code below into the button click event.
Private Sub Command0_Click()
DoCmd.OpenForm "name_of_your_form"
End Sub
That should be all you need to do. Sometimes I have seen Access do some really weird stuff. If the steps I outlined here don't work, try doing a Compact and Repair to reset everything in your DB, and then add the button.

How to show windows form when a custom ribbon button is clicked

I am creating a Word Addin using Visual Studio 2008 with Visual Basic language. I have created a custom ribbon group and a button name "Show_Form". I want that when I click on that button a windows form named "Form" will show.
Sub Button1_Click()
Form.show()
End Sub
It showing a error. Can you please help me.
There is no form called "Form"
You will need to do Form1.Show or Form2.Show etc
However it is good practice to name the forms to what they will be used for otherwise it can become difficult to understand the program code if everything is named so that it doesn't actually identify what it does.

Showdialog and Focus (incredible)

I noticed a strange problem in VB.NET 2010.
If I call showdialog in a TextBox_LostFocus, when I close the form it causes a Loop, but ONLY if I pass from the first textbox to the second USING THE MOUSE! If I use tab it works normally.
I show whith an example:
Create New project and create two forms, form1 and form2
In form1, create two textboxes.
In the textbox1.lostfocus, paste the following code
VB.NET Code:
Dim f As New Form2
f.ShowDialog()
Now: the focus is on textbox1. Right?
If you move to textbox2 with tab key, form2 appears. If you close it it's all normal
BUT if you move to textbox2 using the mouse, form2 appears and if you close it another form2 appears, until 23 times when you get an exception
I workarounded it moving the "dim" statement in declaration area of form1, but anyone has an idea of why of that behaviour?
Thanks in advance.

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.

How do I set the default form in vb.Net?

How do I set form number four as the default form that will run when I press on f5 in visual studio 2008. Because form 1 will always be the first to start
Right-click on your project in solution explorer.
Choose properties.
Select the Application Tab.
Select your form from the dropdown under 'startup form'
In the Project Properties, there's a field called "Startup form" - select your form in there.
Right-click your Project within the Solution Explorer.
Choose Properties.
Select the Web tab on the left-hand side.
Under the Start Page section, define the Specific Page you would
like to default to when the application is launched.
Save your changes.
Right-click your Project within the Solution Explorer.
Choose Properties.
Select the Web tab on the left-hand side.
Under the Start Page section, define the Specific Page you would like to default to when the application is launched.
Save your changes.
The other solutions work, but they will disable the use of ApplicationEvents like Startup, because the startup object has to be Sub Main for those to work.
To change the form started by Sub Main, do the following:
Close your project in Visual Studio.
Open your project's folder in explorer.
In it, open folder My Project.
Open Application.myapp with any text editor.
Change the form between the <MainForm> tags to your (new) main forms name.
Save and close.
Open ApplicationDesigner.vb with any text editor.
Find the following line and change YourMainFormsName to your (new) main forms name:
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.YourProjectsName.YourMainFormsName
End Sub
Save and close.
Open your project again and start it up. The startup form should have changed.
In my case, it doesn't work immediately from project properties. I have to close the solution and re-open it in order to see the latest form you have created and if you intend to make a startup object.