473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

vb.net startup/form load

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
8 26766
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
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
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
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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Imayakumar | last post by:
Hi, I got two forms, named Form1 and Form2 ion a VB.NET Windows application.. by default if i run the application, Form1 gets launched..i need to set Form2 as the startup form how do i do it??...
6
by: Chris Thunell | last post by:
Right now I have a vb.net windows form project that does a whole bunch of things on the form.load event. The problem with this is that the user does not see the form until all the those things are...
1
by: John Michael | last post by:
I have created some password routines to protect certain forms from access without a password. This allows me to create some security for apps that will be used on diff machines for users that...
1
by: Able | last post by:
Dear friends My app load the startup form and all of its controls step by step and its indeed not nice. Do somebody know how to hide the form until the painting is finished? Regards Able
4
by: Chris Ashley | last post by:
I have a class called App set as the startup object with the following code: Friend Class App Shared Sub Main() Dim FrmMain As New MainForm Application.Run(FrmMain) End Sub End Class In...
3
by: JAPSTER | last post by:
An application has a startup form (Form1). A second form (frm2), created from within Form1. Each form has a textbox. To access the text in TextBox1 in frm2 from Form1, you use: ...
4
by: Johnnie Miami | last post by:
I'm using VB.Net 2005 beta 2 and have my login form (login.vb) specified as the startup form. If the user is successful logging in, I call my main form (main.vb). This all works fine but the...
10
by: Bernie Hunt | last post by:
This is probably a silly question, but I've gotten myself confused. My app has two forms, form1 and form2. form1 is the start up object in the propers. An event in form1 instantiates form2. ...
1
by: Jason Richmeier | last post by:
I am experiencing some unexpected behavior with the Form Load event in a Windows application. Hopefully, someone can explain why this behavior is occurring. In my application, I have a form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.