Jump to content
Xtreme .Net Talk

Starting the Application


Recommended Posts

Guest littledump
Posted

Ok i think i know what my problem is & how to fix it if someone just answers this one question. How do i start an app so that no form is specified as the startup form, but i can show a form right after its started.

 

Heres what I have right now but doesnt work

 


Module Hi
   Public Sub Main()
          System.Windows.Forms.Application.Run(Myform)
   End Sub
End Module

 

 

Im sure this is probably an easy question & anyone who helps, thank you.

Guest littledump
Posted

Forgot to mention

 

I forgot to add something to the top of that

 

 


Module Hi
   
    Public Myform as New Form1

    Public Sub Main()
           System.Windows.Forms.Application.Run(Myform)
    End Sub

End Hi

 

the problem is whatever form i put in the Run() method, i can never hide that form. it comes back. i can hide any other form though. thats why i want to know other ways of starting in sub main().

Guest Perl
Posted

'Myform.ShowDialog()'

 

*Should Work*

 

The Application.Run(FormName)

 

Is a pretty messy way to run forms, because you can only have one open that way @ a time, or you can use that to start then use the ShowDialog to open the rest, but remember again you can only have one Run per thread :)

 

Hope ThiS hElPs :)

 

Any more questions AiM me, I am still learning to so i like to seach out others problems :)

Guest littledump
Posted
Ok. is that all i put in Main() and nothing else? Will i then be able to hide that form and show another?
Guest Perl
Posted

Ok I think this part of VB.Net needs some explaining due to the overwhelming amounts of posts in numerous forums to be geared towards this problem.

 

*Note: I would like to say that I am leaving my self out to be criticized by all my friends/co-workers, but since I am off work now I can take more time and explain this to you, which will probably be overkill :)*

 

When you call a program to start in 'Sub Main' its starts off as normal but you have to remember that VB.NET is now single threaded unless other wise called, so if you use

 


Dim oSplash as New SplashScreen

Sub Main
   Call oSplash.Show()
End Sub

 

The program runs, shows the form for a split second (or how ever long it takes to load your form), then it comes back to 'Sub Main' at the end of the 'Call' and continues till 'End Sub' is reached and thus your program has ended so VB.NET cleans up all the garbage and "unloads" your program.

 

Our Next Example is with the run command

 


Imports System.Windows.Form.Application
(...)

Dim oSplash as New SplashScreen

Sub Main
   Call Run(oSplash)
End Sub

 

Now this one runs just fine to people who are loading just one form, or people who will never de-allocated the memory that is used in oSplash. The run command does not leave a return memory call on the stack, so that once your program has terminated there is actually an error. That error doesn�t actually show up on the screen because it is taken care of in the clean up, this error comes from the fact that Windows does not know where in the code you want to return to, thus it becomes confused and faults, UNLESS you tell your code where to go when the memory has been de-allocated.

 

 


Dim oSplash as New SplashScreen

Sub Main
   Call oSplash.ShowDialog()
End Sub

 

This one will load the form, and leave the memory return on the stack. So this one will run the form and as long as you don�t de-allocated the memory of the form it will continue to run, and once the memory is de-allocated it will return to the point just below the line that made the call.

 

There also seems to be some confusion in what the '.Hide' actually does in your eyes. '.Hide' actually de-allocated the memory. There for when you are using this call it comes out of the 'Run' with an error and it cleans up after its self. What you actually want to use is the '.Visible' property that �hides� the form from the users eye. This allows you to keep control over the program and do what you wish while having your main form invisible.

 

Hope This Helps

 

--Perl

-- LbS @ http://www.PcTechForums.com

Guest littledump
Posted

Actually changing the visible property does the same thing. What the problem is, is when I try to set the visible property of the form that i use Run() on, as soon as the Sub that I change the property in exits the form comes back onto the screen. This only happens for the form that I use Run() on. Try this in VB.NET and suggest how without making major changes I can make it run correctly.

 


Module VarsDimsEtc

    Public SplashForm as New Form1()
    Public MainForm as New Form2()
    
    Public Sub Main()
        System.Windows.Forms.Application.Run(SplashForm)
    End Sub

End Module

Public Class Form1
     Inherits System.Windows.Forms.Form
    
    +/Windows Form Generator Code\

    Private Sub Frm_Load (sender as System.Object, e as System.EventArgs) Handles MyBase.Load
         SplashForm.Visible = True
         [sTATEMENT BLOCK]
         MainForm.Visible = True
         SplashForm.Visible = False
    End Sub
End Class

Public Class Form2
    Inherits System.Windows.Forms.Form

    +/Windows Form Generator Code\

    Private Sub Frm_Load (sender as System.Object, e as System.EventArgs) Handles MyBase.Load
              [sTATEMENT BLOCK]
    End Sub
End Class

 

I know there are some obvious things that you think may work but most likely I have tried them. So please set up a program like this and try it.

Guest Perl
Posted


*

    Public SplashForm as New Form1()
    Public MainForm as New Form2()
    
    Public Sub Main()
        System.Windows.Forms.Application.Run(SplashForm)
    End Sub

*

 

Like i said before try not using the Run Command... turn it into...

 

*

    Public SplashForm as New Form1()
    Public MainForm as New Form2()
    
    Public Sub Main()
         Call SplashForm.ShowDialog()
         Call MainForm.ShowDialog()
    End Sub
*

 

This will wait till you have completed what you need to do in the 'SplashForm' then once it is complete it will Run Your 'MainForm'

Guest littledump
Posted

this doesnt work. i still cant get the splash form to hide at the point i want it. i did once but then when i close the main form it comes back. when i use showdialog, the splash shows but wont hide then the main shows on top of the splash

 

the splash wont hide

Guest Perl
Posted
Do you need the splash after the application starts ?
Guest Perl
Posted

About 'Call'...

 

You are right there is no need to have it, you just have to understand the job i am @ and how pickey they are, call makes it known that it is a function call. that is why they like us using it :p any ways its good format practice :)

Guest littledump
Posted
nope dont need splash later but ive tried both .close & .dispose & its still there. mebbe if u pm me ur email ill email u the actual prog i am working on & you can take a look. i just wanna be able to hide :(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...