By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

vb.net startup/form load

P: n/a
This is my first shot at a Winforms application in dot net. This application
is mainly going to run unattended but is using a form to display current
activity of the background processing. In VB6, I could set the startup to be
Sub Main and then call frmMain.Show and the program would continue
processing; however, after instantiating the from in VB.Net - dim frmMain as
new frmMain, frmMain.show shows the form then closes the form to continue
processing - which is counter to my purposes... so I tried
Application.Run(frmMain). This stops program execution until the used does
something.

SO... any help with that? Also, I looked to see if there was a
frmMain_loaded event to call a public sub but I did not see any event that
is fired after the form is loaded and shown.

Any insight would be appreciated.

Brian

Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi Brian,

What code closes the form? If you call the form and nothing in the form's
load event closes it, it should remain open. Can we see some code?

Bernie Yaeger

"Brian Fulford" <br***********@newsgroup.nospam> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
This is my first shot at a Winforms application in dot net. This
application
is mainly going to run unattended but is using a form to display current
activity of the background processing. In VB6, I could set the startup to
be
Sub Main and then call frmMain.Show and the program would continue
processing; however, after instantiating the from in VB.Net - dim frmMain
as
new frmMain, frmMain.show shows the form then closes the form to continue
processing - which is counter to my purposes... so I tried
Application.Run(frmMain). This stops program execution until the used does
something.

SO... any help with that? Also, I looked to see if there was a
frmMain_loaded event to call a public sub but I did not see any event that
is fired after the form is loaded and shown.

Any insight would be appreciated.

Brian

Nov 21 '05 #2

P: n/a
The form should remain open until someone closes it with the 'X' or until an
error causes an unrecoverable exception.

I have the following code in a module
*****************************************

Public WithEvents frmMain As New frmMain
Sub Main()

Application.Run(frmMain)

startConfiguration()

startExecution()

End Sub

*****************************************

The FORM is basically a txtbox/treeview that will contain error messages or
the contents of the threads that are currently working. There is a close
button on the form so that the program execution can be interrupted and
processing cautiously shut down via thread aborts etc. At least that is the
plan thus far!

I want the form to be shown, and then have processing continue in the sub
main().
"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Brian,

What code closes the form? If you call the form and nothing in the form's
load event closes it, it should remain open. Can we see some code?

Bernie Yaeger

"Brian Fulford" <br***********@newsgroup.nospam> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
This is my first shot at a Winforms application in dot net. This
application
is mainly going to run unattended but is using a form to display current
activity of the background processing. In VB6, I could set the startup to be
Sub Main and then call frmMain.Show and the program would continue
processing; however, after instantiating the from in VB.Net - dim frmMain as
new frmMain, frmMain.show shows the form then closes the form to continue processing - which is counter to my purposes... so I tried
Application.Run(frmMain). This stops program execution until the used does something.

SO... any help with that? Also, I looked to see if there was a
frmMain_loaded event to call a public sub but I did not see any event that is fired after the form is loaded and shown.

Any insight would be appreciated.

Brian


Nov 21 '05 #3

P: n/a
What would actually be preferable would be to have the FORM be the startup
object.. and after the form is loaded.. to call startConfiguration with no
user click event... how do you know when the form is finished loading in
VB.Net?

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Brian,

What code closes the form? If you call the form and nothing in the form's
load event closes it, it should remain open. Can we see some code?

Bernie Yaeger

"Brian Fulford" <br***********@newsgroup.nospam> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
This is my first shot at a Winforms application in dot net. This
application
is mainly going to run unattended but is using a form to display current
activity of the background processing. In VB6, I could set the startup to be
Sub Main and then call frmMain.Show and the program would continue
processing; however, after instantiating the from in VB.Net - dim frmMain as
new frmMain, frmMain.show shows the form then closes the form to continue processing - which is counter to my purposes... so I tried
Application.Run(frmMain). This stops program execution until the used does something.

SO... any help with that? Also, I looked to see if there was a
frmMain_loaded event to call a public sub but I did not see any event that is fired after the form is loaded and shown.

Any insight would be appreciated.

Brian


Nov 21 '05 #4

P: n/a
Hi Brian,

You can make the form's vb code the startup routine - go into the project
menu, [project name] properties etc. A form is loaded when the load event
concludes. I still don't see enough code to explain what is happening.

Bernie Yaeger

"Brian Fulford" <br***********@newsgroup.nospam> wrote in message
news:Ob**************@TK2MSFTNGP09.phx.gbl...
What would actually be preferable would be to have the FORM be the startup
object.. and after the form is loaded.. to call startConfiguration with no
user click event... how do you know when the form is finished loading in
VB.Net?

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi Brian,

What code closes the form? If you call the form and nothing in the
form's
load event closes it, it should remain open. Can we see some code?

Bernie Yaeger

"Brian Fulford" <br***********@newsgroup.nospam> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
> This is my first shot at a Winforms application in dot net. This
> application
> is mainly going to run unattended but is using a form to display
> current
> activity of the background processing. In VB6, I could set the startup to > be
> Sub Main and then call frmMain.Show and the program would continue
> processing; however, after instantiating the from in VB.Net - dim frmMain > as
> new frmMain, frmMain.show shows the form then closes the form to continue > processing - which is counter to my purposes... so I tried
> Application.Run(frmMain). This stops program execution until the used does > something.
>
> SO... any help with that? Also, I looked to see if there was a
> frmMain_loaded event to call a public sub but I did not see any event that > is fired after the form is loaded and shown.
>
> Any insight would be appreciated.
>
> Brian
>
>
>



Nov 21 '05 #5

P: n/a
Hi Brian,

I think we can run a invisible winform first to enable the message pump
which will drive the application code, which is different from VB6. Because
VB.NET is based on .NET framework which has the different behavior from VB6.

For your scenario, we can use the code as below.
[Module]
Module Module1
Sub Main()
Dim fm As New Form1
fm.Visible = False
fm.WindowState = Windows.Forms.FormWindowState.Minimized
System.Windows.Forms.Application.Run(fm) 'Enable the message pump,
so that the thread will not exit after the other form is closed.
End Sub
End Module

[Form1]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Visible = False
Dim fm As New Form2
fm.Show()
MsgBox("Hello")
End Sub

[Form2]
Private Sub Form2_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
System.Windows.Forms.Application.Exit()
End Sub

You may have a try to let me know if that works for you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

P: n/a

"Brian Fulford" <br***********@newsgroup.nospam> wrote
The form should remain open until someone closes it with the 'X' or until an
error causes an unrecoverable exception. <...> I want the form to be shown, and then have processing continue in the sub
main().

See if this helps, in a new poject, add a module and paste in the code below
then, set the project Startup object to the Sub Main routine. As shown, the
module processing updates the form's caption with the current time. If
you don't see the time displayed, then you forgot to set the Startup object.

LFS
' [ FORM1 CODE ]
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
Done = True
End Sub

Private Sub Form1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Click
' Unhandled exception (Divide by 0)
Dim a, b, c As Integer
a = b \ c

End Sub

' [ MODULE1 CODE ]

Public Done As Boolean
Public Display As Form1

<STAThread()> Sub Main()
Display = New Form1
Display.Show()

Do While Not Done
Processing()
Try
Application.DoEvents()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error Caught!")
End Try
Loop

' Clean up code
MsgBox("Clean up complete")

End Sub

Private Sub Processing()
' Update display
Display.Text = Now.ToLongTimeString
System.Threading.Thread.Sleep(250)
End Sub

Nov 21 '05 #7

P: n/a
Larry, thanks for the heads up on this.I suppose I just needed that DO ...
Loop with the public boolean to make it work like I wanted.

Sub Main()

MainFormDisplay = New frmMain

MainFormDisplay.Show()

Try

If startConfiguration() Then

startExecution()

Do While Not doExit

Application.DoEvents()

Loop

Else

Do While Not doExit

Application.DoEvents()

MainFormDisplay.txtDisplay.Text = lastError

System.Threading.Thread.Sleep(25)

Loop

End If

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error Caught!")

End Try

End Sub

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uF**************@TK2MSFTNGP14.phx.gbl...

"Brian Fulford" <br***********@newsgroup.nospam> wrote
The form should remain open until someone closes it with the 'X' or until an error causes an unrecoverable exception. <...>
I want the form to be shown, and then have processing continue in the sub main().

See if this helps, in a new poject, add a module and paste in the code

below then, set the project Startup object to the Sub Main routine. As shown, the module processing updates the form's caption with the current time. If
you don't see the time displayed, then you forgot to set the Startup object.
LFS
' [ FORM1 CODE ]
Private Sub Form1_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _ Handles MyBase.Closing
Done = True
End Sub

Private Sub Form1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Click
' Unhandled exception (Divide by 0)
Dim a, b, c As Integer
a = b \ c

End Sub

' [ MODULE1 CODE ]

Public Done As Boolean
Public Display As Form1

<STAThread()> Sub Main()
Display = New Form1
Display.Show()

Do While Not Done
Processing()
Try
Application.DoEvents()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OKOnly, "Error Caught!")
End Try
Loop

' Clean up code
MsgBox("Clean up complete")

End Sub

Private Sub Processing()
' Update display
Display.Text = Now.ToLongTimeString
System.Threading.Thread.Sleep(250)
End Sub

Nov 21 '05 #8

P: n/a
Hi Brian,

If you still have any concern on this issue please feel free to post here.
Also have you tried my suggestion? Do you have any concern?
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.