I have problem about close() or dispose() function with my barcode reader (Windows Embedded Compact 7). In this case I can only hide() form.
I tried to show Form2 as dialogue but after I clicked the close button (to hide this form and go back to Form1) It made all of my application close
In Form1 (Main):
Public Sub showForm2()
Dim secForm As New Form2
secForm.ShowDialog()
End Sub
In Form2:
'close button
Private Sub closebt_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles closebt.Click
Me.Hide()
End Sub
Form can't be hidden if it is shown as Dialog. If you want to hide the form then use form.show() rather than form.ShowDialog(). Also here is a link
http://www.vbforums.com/showthread.php?759061-How-can-i-hide-my-second-form-dialog-without-bliking-form-not-closing-my-first-form
Go to properties page of the project. In the Application tab, there is a setting:
Shutdown mode
When startup form closes
When last form closes
Choose "When last form closes" to prevent closing the application when your main form closes.
in the index form add in form closing the fallow code:
Form1.Dispose()
Related
When i login into my application and i get to the menu form, after the form triggers the form.shown after 1 second timer i start an update procedure.
This procedure calls another form which is on top the menu form, and does certain things.
This update form can also be called from a button that is on the menu form.
The problem here is when i call this form from the button the taskbar is hidden and also the menu form which is at the back is unclickable(I set my application to be full screen so taskbar is not visible). When the update form opens from the timer the taskbar appears, and the menu form which is at the back is clickable, and the user can click buttons from the parent form.
I tried setting focus on the update form after is loaded from the processes of windows but it didn't change anything.
I dont want to show the taskbar nor have clickable parent form.
Any idea why is this happening and how can i fix it?
Here is how i call my form from timer and from the button:
Private Sub TimerDelayedStart_Tick(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs)
TimerDelayedStart.Stop()
LoadUpdateDatabase()
End Sub
Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
LoadUpdateDatabase()
End Sub
Private Sub LoadUpdateDatabase()
Try
fUpdateDatabase = New frmUpdateDatabase
With fUpdateDatabase
.ShowDialog()
Cursor = Cursors.Default
End With
Catch ex As Exception
End Try
End Sub
Disclaimer: I only have beginner to slightly intermediate experience with VB.net
Hello, I was tinkering around with some design ideas for a project and I ran into a problem that I haven't found a solution to. I have a win form with some buttons and a panel. When the user presses a button, a border-less form is loaded into the panel. The problem is this: when the main form is closed, Visual Studio does not stop debugging, presumably because the forms in the panel are not disposed of.
Win Form image
The instance of the panel form is declared in the button click event. How can I destroy that instance from another sub? If I click another button, the first panel form doesn't go away. Is there a better way to accomplish this? I'm still learning, so I'm often not aware of all the different ways to solve a problem. Thanks everyone!
Public Class frm_Clients
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim search As New Search
search.TopLevel = False
search.Dock = DockStyle.Fill
Panel1.Controls.Add(search)
search.Show()
End Sub
Private Sub frm_Clients_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
' What should I write here?
End Sub
End Class
Here's a snippet of what to do to close the windows when another button is pressed.
For Each form In Panel1.Controls.OfType(Of Form).ToList()
form.Close()
Next
Then I would suggest that you set search.Owner to the Form holding the Panel. That means that when the Owner is closed, so are the children.
search.Owner = Me
I have a welcome to my application as it loads up, but then need to have that form close and login form open when the continue button is hit.
My code:
Me.Close()
Dim Login As New Form
Login.Show()
When I click the button it only closes the welcome form and then ends the application. If you can help thanks! :)
You can set the properties of the project to select "When last form closes" in the shutdown mode dropdown
Update:-
"Project" menu -> 'YourApp' Properties... -> Application Tab
find : "Shutdown Mode"
Change from
"When startup form closes" --> "When last form closes"
show the form before the close.
Dim Login As New Form
Login.Show()
Me.Close()
Better is if you use Me.Hide()
There is a shutdown mode project property. This controls the application lifecycle.
Make sure you set this to "When last form closes"
Then your code should work as you expect.
What is happening is that you have that setting set to shutdown "when startup form closes", so by doing Me.Close on the startup form, this shuts down the application, all code after this line is effectively ignored.
If your Welcome Form isn't your main form, you just need to put your Me.Close after your Login.Show()
Dim Login As New Form
Login.Show()
Me.Close()
Try this..
On your welcome form when closing:
Me.hide()
Dim Login As New Form
Login.Show()
On your login form when in loading event:
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WelcomeForm.Close()
End Sub
This will try to hide the first form and load the second form. And when second form is completely loaded it will try to close the first form.
Make sure that on your Application Tab under your Project properties the option is set to "When last form closes".
If you close sub main form from application, your application will close. However, you can close and open other forms if they are not the sub main form. Maybe you can just hide it instead.
You just need to put Hide() instead of Close :)
So for example, in the project im doing right now...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click // Button1.Click is your "continue" button
Hide()
LogInFrom.Show()
End Sub
I have 2 forms on my application. I have the main form that opens TopMost, CenterScreen and Maximized. Then I have another form on this screen that pops open when I press a button. That second screen has a button that navigates to another screen, so when I press that button the second form closes, and the main form is suppose to close as well and the selected sheet open up.
However, the second screen closes fine, but my main screen remains open and active, while the called sheet opens but does not enable. I track down what was happening and the issue is that form all code runs, but the main screen does not seem to want to close. Here is my code:
Private Sub btnOpenDashboard_Click(sender As Object, e As EventArgs) Handles btnOpenDashboard.Click
Dim welcomeForm As New frmWelcomePage
If lblReportTitle.Text = "Employee Dashboard" Then
Me.Close() 'This works
welcomeForm.Close() 'This one remains open and active
Globals.dsbEmployeeBoard.Select() 'This one opens but is not enabled
End If
End Sub
I assume from your description that you already have a welcome form created and displayed before the form with the button is displayed.
This line of code:
"Dim welcomeForm As New frmWelcomePage"
is creating a new copy of the Welcome Page and closing it.
Instead of creating a new one, you need to reference the original one that is open.
If I recall correctly, you should be able to just remove that line and use frmWelcomPage.Close.
You need to pass a reference of your first form (Form1) to the second form (Form2), so that in the second form you can close the first form, like this:
Public Class Form2 Inherits Form
Private _form1 As Form1
Public Sub New(form1 As Form1)
Me.Form1 = form1
End Sub
End Class
Private Sub btnOpenDashboard_Click(sender As Object, e As EventArgs) Handles btnOpenDashboard.Click
If lblReportTitle.Text = "Employee Dashboard" Then
_form1.Close()
End If
End Sub
Then when you instantiate Form2, you would pass a reference to Form1, like this:
Dim form2 As New Form2(Me)
Note: Me is the instance of Form1.
In the main form "frmMain.vb" I have a button that when it is clicked runs the following code:
Dim myform as New frmMyDialog
myform.ShowDialog()
On the "frmMyDialog.vb" form the user can start a public function of the main form and I need to hide the dialog until the function ends, so I wrote this code:
Private Sub btnStartProcess_Click(sender As System.Object, e As System.EventArgs) Handles btnStartProcess.Click
'hide the dialog
Me.Hide()
'start the sub of the main form
frmMain.TestSub()
'close the dialog
Me.Close()
End Sub
However, when the dialog becomes hidden, the main form is minimized. How can I hide the dialog without also hiding the main form?
(The "formBorderStyle" property of "frmMyDialog.vb" is "FixedDialog", I don't know if it can help.)