9 Replies - 1034 Views - Last Post: 30 October 2015 - 06:00 PM Rate Topic: -----

#1 alazeem37   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-October 15

how to change startup form by button clicking for restart

Posted 29 October 2015 - 09:13 AM

Hi
Today My problem is I couldn't change my start up form with application restart . So I only tried
Application.Restart()
but I Don't know how to program it . Here I used a buttion for restart . The reason for change startup form , my startup form is a splash screen so if i resatrt my application it would be come to main form . I don't know how to resolve it. Could you Please try to help me

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: how to change startup form by button clicking for restart

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5543
  • View blog
  • Posts: 14,547
  • Joined: 18-April 07

Re: how to change startup form by button clicking for restart

Posted 29 October 2015 - 11:57 AM

Well one way you could do it is in the project properties set the startup object to sub main. This will cause the application to run what is in the sub main method during startup. In there, you can write logic that will then launch whatever form, based on whatever conditions you want, during startup.

https://msdn.microso...(v=vs.120).aspx

This will give you the most flexibility and allow you to build complex scenarios of when each form should be shown on startup. :)

This post has been edited by Martyr2: 29 October 2015 - 11:58 AM
Reason for edit:: Added sub main reference link

Was This Post Helpful? 0
  • +
  • -

#3 alazeem37   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-October 15

Re: how to change startup form by button clicking for restart

Posted 29 October 2015 - 11:22 PM

View PostMartyr2, on 29 October 2015 - 11:57 AM, said:

Well one way you could do it is in the project properties set the startup object to sub main. This will cause the application to run what is in the sub main method during startup. In there, you can write logic that will then launch whatever form, based on whatever conditions you want, during startup.

https://msdn.microso...(v=vs.120).aspx

This will give you the most flexibility and allow you to build complex scenarios of when each form should be shown on startup. :)/>



I couldn't understand what are you saying

I would like to change my startup form while application restart
Was This Post Helpful? 0
  • +
  • -

#4 maceysoftware   User is online

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,659
  • Joined: 07-September 13

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 04:29 AM

Hello Martyr2 way is quiet straight forward however it does seem, and for the life of me please correct me if i am wrong because this doesn't sound right to me. you can only change the main the start-up object to sub main in a console application...

So you have two choices even change your application type to be a console application or you can change the code in the background directly.

The second option will be a bit of hit and miss (possibly) i have never done this but if you:

Click the button on the solution explorer to show hidden files
Expand My Project
Expand Application.myapp
Open Application.Designer.vb

There is a routine in this class called 'OnCreateMainForm', this routine goes along and creates the main form, you could put code in to find out what form should be set-up and then change the code appropriately.

For example i have got my startup form set to form1 however in this routine i am calling form2.

        <Global.System.Diagnostics.DebuggerStepThroughAttribute()>  _
        Protected Overrides Sub OnCreateMainForm()
            Me.MainForm = Global.WindowsApplication1.Form2
        End Sub



Now how you need to find out what form to open could be the difficult part, as your restarting the application variables will also be reset, so holding this information in a variable is pointless, ideally you have 3 ways, you could write it away to the database, file system or registry.


Leaving the above there for future people to look at but i wouldn't recommend it, after thinking about it.

OR

you could keep the main form as form1 for example and on load hide the form and show the correct form? this is a lot simpler way thinking about it.

what about if you bring up a splash screen first? that splash screen can then do the logic on what form to launch and launch the correct form.

It all really depends on what your comfortable doing, if your a beginner you may want to stay away from the project designer files, if your happy modifying them then go ahead.

What i would STRONGLY recommend if your going to go ahead with modifying the designer files is create a test application and try on their, after that back-up your designerfile so if all goes wrong all you have to do is close the VS down and restore the back-up and launch again and it will all be working (hopefully)

This post has been edited by maceysoftware: 30 October 2015 - 06:03 AM

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is offline

  • a lovely bit of linq
  • member icon

Reputation: 6891
  • View blog
  • Posts: 28,512
  • Joined: 12-December 12

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 04:55 AM

maceysoftware said:

for the life of me please correct me if i am wrong because this doesn't sound right to me. you can only change the main the start-up object to sub main in a console application...

In WinForms the Main would be manually created:
Public Sub Main()

    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
    Application.Run(New Form1)

End Sub

there is no need to use the Designer.

Quote

so holding this information in a variable is pointless, ideally you have 3 ways, you could write it away to the database, file system or registry.

There are Application Settings to consider. If the intention is simply to have an option "do not show this again" for the splash screen then a user-level application setting, a boolean value, could be used.

This post has been edited by andrewsw: 30 October 2015 - 05:35 AM

Was This Post Helpful? 0
  • +
  • -

#6 maceysoftware   User is online

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,659
  • Joined: 07-September 13

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 06:05 AM

Hello Andrew,

I had already attempted to create a manual Sub Main however it wouldn't appear in the list of start-up objects, can you point me in the direction of where this would have to be?

Originally i had it in a class, changed it to a module and still doesn't appear, just for my own curiosity.

I was also covering application settings in terms of file system, sorry for being confusion.

and the penny drops, the combobox actually reads start-up form for winforms applications and therefore you would need to do something like my second idea.
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is offline

  • a lovely bit of linq
  • member icon

Reputation: 6891
  • View blog
  • Posts: 28,512
  • Joined: 12-December 12

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 06:08 AM

Create a new Module named Program.vb and add the Sub Main to it from above.

Go to the Project Properties, Application tab. Uncheck "Enable Application Framework" then choose Sub Main from "Startup Object".
Was This Post Helpful? 1
  • +
  • -

#8 maceysoftware   User is online

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,659
  • Joined: 07-September 13

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 06:17 AM

Excellent,

Thank you Andrew for that, will have to remember that one.
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is offline

  • a lovely bit of linq
  • member icon

Reputation: 6891
  • View blog
  • Posts: 28,512
  • Joined: 12-December 12

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 06:24 AM

No worries.

The module doesn't need to be named Program, but it makes sense. In the startup list you can select the Module, rather than Sub Main, because it will look for Main in the Module. This allows us to have more than one Main available.
Was This Post Helpful? 0
  • +
  • -

#10 alazeem37   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 24-October 15

Re: how to change startup form by button clicking for restart

Posted 30 October 2015 - 06:00 PM

Dear Sirs

I couldn't Understand what are you saying
can you please tall me step by step

Dear Sirs

I couldn't Understand what are you saying
can you please tall me step by step ?

Dear Sirs

I couldn't Understand what are you saying
can you please tall me step by step ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1