• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Dialog Application

Hi

I need some advice on an application I am writing in VB.Net.

I have created a new Windows Forms application and to this I have added a standard Splash Screen (Project->Add New Item->Splash Screen). Then I have set the startup form set as the default form created when the application was created i.e. Form1.

This all works but it doesn't feel right to me. What I would prefer is that a module deals with the creation of the various forms in the application together with all the global variabes etc.

At the moment Form1 will appear and then depending on buttons I press on it, other forms will be opened and Form1 should be destroyed.

I am from a C++ background so really I am looking for advice on how to write an application where:

(1) A Splash Screen appears on startup.
(2) A form appears afterwards on which various buttons are displayed. Pressing any of these buttons displays a new form (and in most cases the parent form will no longer be necessary and should probably be removed).

To summarise, I need advice on how to achieve a common area where all these forms are dealt with e.g. a module.

Hope you can help.

Issac
0
IssacJones
Asked:
IssacJones
  • 11
  • 7
  • 3
  • +1
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I suggest you use the approach outlined in my article here:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/A_2729-Building-a-Formless-WinForms-Application-with-a-NotifyIcon-in-VB-Net-2008.html

By using an ApplicationContext, you can freely open and close forms without the application closing on you.
0
 
AmbusyCommented:
Create a moduke:
Module Module1
    Public Sub main()
        Dim myFrm As New Form1
        Application.Run(myFrm)
    End Sub
End Module

Open in new window

where you add anything before running the form.
In the Application Tab of your Project in the solution, disable "application framework" and then choose sub main as startup object.
Main waits until Form1 closes before proceeding, so you need to open other forms in Form1.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*There is actually a setting in Project --> Properties to allow the main form to be closed without the app shutting down.  It's the "Shutdown Mode" dropdown with a setting of "When last form closes".  As long as you open another form before closing the current one the app will stay open.

The ApplicationContext approach, though, would be a great way to deal with the authors requirement below:

    "What I would prefer is that a module deals with the creation of the various forms in the application together with all the global variabes etc."
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AmbusyCommented:
If you want to run form1, start others and meanwhile not show form1, you need something in Form1 to close, as it is the main.
following code (for 1 extra form) works fine:
Module Module1
    Public Sub main()
        Dim myFrm As New Form1
        Application.Run(myFrm)
        Dim i As Integer = 1
    End Sub
End Module
Public Class Form1
    Friend DoStop As Boolean = False
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If DoStop Then
            End
        Else
            If Timer1.Interval = 100 Then
                Form2.Show()
                Me.Hide()
                Timer1.Interval = 3000
            End If
        End If
    End Sub
End Class
    Public Class Form2
        Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            Form1.DoStop = True
        End Sub
    End Class

Open in new window

0
 
AmbusyCommented:
Shutdown: I learned soething tonight! txs
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
@Ambusy...see my last post.  =)

Just change the "Shutdown mode" in Project --> Properties so you don't have to do that.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Lol...cross-posted.  Yay!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The ApplicationContext() approach is another way to deal with that scenario too.
0
 
CodeCruiserCommented:
I think it depends on your application and the relationship between different forms. You can have a MDI form and it opens all the child forms on menu commands for example so all the form opening is in the MDI itself. If you want to go further, you can write a method that takes a form name and shows it. Then call this method wherever you need to show a form.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
*Posted in my article:

Hi guys

Thanks for all your comments unfortuntately all seem to have a problem in that if "Enable application framework" is unchecked then the Splash Screen I have added is not called and displayed.

Any ideas?

Issac
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
With the application framework disabled, you'd have to display your splash screen manually.
0
 
IssacJonesAuthor Commented:
Hi IdleMind

Sorry I posted in your other article.

Should I open another question on how to implement the splash screen manually?

Issac
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What approach did you end up using for the core of your app?
0
 
IssacJonesAuthor Commented:
I used the approach used in your article and created a module file which is called.

I guess what I need to do now is transfer the startup of the splash screen to that module.

As I say, the splash screen I am using can be obtained from Project->Add New Item->Splash Screen.

At the moment I can't see how to use it manually and implicitly adding the code.

Issac
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You'd create an instance of it and use the Show() method:
Module Module1

    Public Splash As New SplashScreen1

    Public Sub Main()
        ' Display the Splash and Make sure it Renders:
        Splash.Show()
        Application.DoEvents()

        ' Start the app with our ApplicationContext:
        Application.Run(New MyContext)
    End Sub

End Module

Public Class MyContext
    Inherits ApplicationContext

    Public Sub New()
        ' ... "slow" loading process...
        System.Threading.Thread.Sleep(4000)

        ' Close the Splash form:
        Splash.Close()

        ' ... do something else ...
        Dim f1 As New Form1
        f1.Show()
    End Sub

End Class

Open in new window

0
 
IssacJonesAuthor Commented:
Many thanks guys
0
 
IssacJonesAuthor Commented:
Sorry, but I need to clarify something with Idle_Mind.

When Form1 is closed, the application does not close. How do I close the application?

Issac
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
When you want the application to close, use "Application.Exit()"
0
 
IssacJonesAuthor Commented:
Cheers!!!
0
 
IssacJonesAuthor Commented:
MMMM, not sure now. If I have the following:

Public Class MyContext
    Inherits ApplicationContext

    Public Sub New()
        ' ... "slow" loading process...
        System.Threading.Thread.Sleep(4000)

        ' Close the Splash form:
        Splash.Close()

        ' ... do something else ...
        Dim f1 As New Form1
        f1.Show()

         Application.Exit()

    End Sub

End Class

Then f1 is not diplayed and the application does not terminate i.e. if running the code in the debugger the debugger is still running after reaching Application.Exit() so I think everything has not been closed.

Issac
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can't close it from the New() constructor.  What would be the point anyways?

Place it in a different method that gets triggered somehow (like in response to Form1 closing), or place it in the Form code itself.
0
 
IssacJonesAuthor Commented:
Thanks again - whoops, missed the New constructor!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 11
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now