Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Closing Forms

Posted on 2004-09-10
12
Medium Priority
?
173 Views
Last Modified: 2010-04-23
Hi

When my program loads it will show a login form that i have created. After the user has successfully entered a correct username and password a form is loaded depending on their privelleges. What i want to know is how do you close this main form without shutting down the whole program as it does.

if I open another form then go me.close() the program will shutdown. I can hide the form but when the user closes the other window i displayed to them the program will stay running.

Is there anyway to close the main form without shutting down the program?

thanks
0
Comment
Question by:adam_pedley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 10

Expert Comment

by:anv
ID: 12024518
try this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim fr As New Form2()
        fr.Show()
        Me.Hide() 'hide current form
    End Sub
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12024525
if I open another form then go me.close() the program will shutdown. I can hide the form but when the user closes the other window i displayed to them the program will stay running.
0
 
LVL 10

Expert Comment

by:anv
ID: 12024541
use
the keyword

 End
in the event when u want to close the whole application
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Author Comment

by:adam_pedley
ID: 12024550
how would you specify the event of a form closing
0
 
LVL 10

Expert Comment

by:anv
ID: 12024579
hi adam_pedley

what i mean was
when say on form2 u have a button called Close when this button is clicked u want to close the whole application..

then in the click event of close add the statement
End

and the application will close..

0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12024588
but like vb6 isnt there an event that on closing the form, code can be run?
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12024743
Hi Adam,

Question

Some users can get a different form depending on their priviliges,

or

the same form with different controls ?
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12024747
different form
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 12024876
Hi Adam,
 Instead of starting the login form,  make a sub main in a module

like

Imports System.Windows.Forms

Module MainModule
    Public mainForm As mainForm
    Private LoginForm As LoginForm
    Private appContext As ApplicationContext

    Sub Main()
        StartApplication()
        ShowLoginScreen()
        ShowMainForm()
        ReadEvents()
        Cleanup()
    End Sub

    Sub StartApplication()
        appContext = New ApplicationContext()
    End Sub

    Sub ShowLoginScreen()
        LoginForm = New loginForm()
        LoginForm.ShowDialog()
    End Sub

    Sub ShowMainForm()
        mainForm = New MainForm()
        mainForm.Show()
    End Sub


    Sub ReadEvents()
        appContext.MainForm = mainForm
        Application.Run(appContext)
        ' Application will exit when closing mainForm
    End Sub

    Sub Cleanup()
        ' Garbage collection here
    End Sub
End Module
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 1500 total points
ID: 12026318
>>"but like vb6 isnt there an event that on closing the form, code can be run"<< yes there is. Use the "Base Class Event" that is events associated with the form. and pick Form_Closing.
-@Baan
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12026785
The form will be runned in another thread, so your app won't exit.
In your main form

Imports System.Threading


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim t As New Thread(AddressOf RunForm)
        t.Start()
End Sub

 Private Sub RunForm()
        Dim f As New Form1
        Application.Run(f)
 End Sub
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12040332
i decided to run code when the form was closing using the  Handles MyBase.Closed
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question