473,554 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 26781
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.nospa m> wrote in message
news:OR******** ******@TK2MSFTN GP09.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)

startConfigurat ion()

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*****@cherwe llinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.nospa m> wrote in message
news:OR******** ******@TK2MSFTN GP09.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 startConfigurat ion with no
user click event... how do you know when the form is finished loading in
VB.Net?

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.nospa m> wrote in message
news:OR******** ******@TK2MSFTN GP09.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.nospa m> wrote in message
news:Ob******** ******@TK2MSFTN GP09.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 startConfigurat ion with no
user click event... how do you know when the form is finished loading in
VB.Net?

"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.nospa m> wrote in message
news:OR******** ******@TK2MSFTN GP09.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.F ormWindowState. Minimized
System.Windows. Forms.Applicati on.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(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Me.Visible = False
Dim fm As New Form2
fm.Show()
MsgBox("Hello")
End Sub

[Form2]
Private Sub Form2_Closed(By Val sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Closed
System.Windows. Forms.Applicati on.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.nospa m> 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(B yVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _
Handles MyBase.Closing
Done = True
End Sub

Private Sub Form1_Click(ByV al sender As Object, _
ByVal e As System.EventArg s) _
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.DoE vents()
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.OKO nly, "Error Caught!")
End Try
Loop

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

End Sub

Private Sub Processing()
' Update display
Display.Text = Now.ToLongTimeS tring
System.Threadin g.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 startConfigurat ion() Then

startExecution( )

Do While Not doExit

Application.DoE vents()

Loop

Else

Do While Not doExit

Application.DoE vents()

MainFormDisplay .txtDisplay.Tex t = lastError

System.Threadin g.Thread.Sleep( 25)

Loop

End If

Catch ex As Exception

MsgBox(ex.Messa ge, MsgBoxStyle.OKO nly, "Error Caught!")

End Try

End Sub

"Larry Serflaten" <se*******@usin ternet.com> wrote in message
news:uF******** ******@TK2MSFTN GP14.phx.gbl...

"Brian Fulford" <br***********@ newsgroup.nospa m> 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(B yVal sender As Object, _
ByVal e As System.Componen tModel.CancelEv entArgs) _ Handles MyBase.Closing
Done = True
End Sub

Private Sub Form1_Click(ByV al sender As Object, _
ByVal e As System.EventArg s) _
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.DoE vents()
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.OKO nly, "Error Caught!")
End Try
Loop

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

End Sub

Private Sub Processing()
' Update display
Display.Text = Now.ToLongTimeS tring
System.Threadin g.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
336
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?? Thanks. Imaya Kumar J.
6
537
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 done. Is there a way for a form to be shown first AND THEN have it automatically start to run through my code? (perhaps a different event???...
1
5366
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 will not have to learn the whole access security process and me as well. I would like to lockup my database by unchecking all of the options in the...
1
2020
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
3899
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 another form I use the following code:
3
2414
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: frm2.TextBox1.Text = "XXXXXX" How do I refer to the TextBox1 controls Text property in Form1 from frm2? Form1.TextBox1.Text doesn't work and generates a...
4
7833
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 problem is that the login form stays open. I put a me.close (in the login form) after opening the main form but that seems to close everything and the...
10
2982
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. Dim myForm as HardwareStore myForm = New HardwareStore myForm.Show() I understand that my form2 can be referenced by
1
2252
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 that I would like to show multiple times throughout the life of the application. The startup code for this form can be quite lengthy so I am hiding...
0
7783
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8023
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7879
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5426
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5144
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.