Project calling method in one solution - vb.net

Now added 3 projects in one solution.
When I called 2nd projects form calling using this code
Dim frm as New Project2.Form1
frm.show()
Me.Hide()
Now, I want to hidden window to be unhide when I click the exit button in project2.Form1
Project1.Home.Show()
Me.Close()
but in Project2 not showing Project1 at the time of making code

Related

How to show an existing form in a project

Newbie alert!
I'm trying to show another form when a user successfully inputs the correct username and password. Like a login screen
But on button click event, the code below is highlighted
Form2.Show()
The second form won't show and the code above has wiggly lines below it
This error shows: Property access must assign to the property or use its value
What can be the problem?
You should create an instance of your form.
On button click event,
Dim frm2 As New Form2()
frm2.Show()
Do not use shared (static) method to display form. Use instance method instead.
Code below will display Form2 modally and after that, disposes it.
Using f2 As New Form2
f2.ShowDialog(Me)
End Using

How to iterate through open forms in a VSTO add-in?

I have a VSTO add-in for MS Project that opens forms where the data is related to the specific project file that was active when the form was open. It is possible to open one form related to one project file, while having another different form open that is related to a second open project file.
When I close a project file I would like to check each open form, and close it if the forms base project ID equals the project ID of the project file that is closing. How do I access the open forms collection of the vsto application (or do something equivalent)? The Application.OpenForms object doesn't appear to exist in the vsto world.
Use a Dictionary object to store an instance of the form along with the name of the file. Every time a form is created, add it to the dictionary and when the project is closed, search the dictionary to close the appropriate copy.
Friend ProjectForms As New Dictionary(Of String, MyForm)
Friend Sub ShowForm()
Dim f As New MyForm
Try
ProjectForms.Add(ProjApp.ActiveProject.Name, f)
Catch AlreadyInTheDictionary As Exception
' do nothing, it's already in the dictionary
End Try
f.Show()
End Sub
Put this in the module with the application events (typically ThisAddIn).
Private Sub Application_ProjectBeforeClose(pj As MSProject.Project, ByRef Cancel As Boolean) Handles Application.ProjectBeforeClose
ProjectForms(pj.Name).Close()
End Sub

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.

VB using me.close before opening new form

Hi Guys i'm new to Visual Basic Coding, and i can't seem to get where's my mistake on my coding, i'm trying to create a button that opens a new form while closing the current form.
i have two forms, form 1 is MainForm, form 2 is SearchForm
Whenever i use this code:
Private Sub SearchMButton_Click(sender As Object, e As EventArgs) Handles SearchMButton.Click
MainForm.Close()
SearchForm.Show()
End Sub
End Class
it will generate an error and says i need to replace MainForm.Close() into Me.Close()
When i Use this
Private Sub SearchMButton_Click(sender As Object, e As EventArgs) Handles SearchMButton.Click
Me.Close()
SearchForm.Show()
End Sub
End Class
It closes both Forms and it doesn't leave any Form Open. Kindly direct me to the proper path, thanks in advance.
You need to Hide the form rather than closing it. Since it's your main form, when it closes, the application exits.
Standard UI guidelines are to leave the main form open, and open search form on top of that. If you need to block the main form, while search criteria are selected, use .ShowDialog, instead of just .Show.
.NET WinForms programming pattern kind of implies that you never close your main form. If you deviate from this approach, you are guaranteed to encounter all sorts of layout and display issues. So please don't. You can .Hide the main form, if it needs to go to system tray or run in background.

Showing form 2 before form 1

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