473,386 Members | 1,830 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.

Showing Form in Sub Main

I have a Sub Main from which I show a Form:

Public MainForm as New Form1
<STAThread()> Public Sub Main()
MainForm.Show()
Application.Run()
End Sub

The MainForm (Form1) shows ok and runs ok until I show a Form2 from Form1.
This works Ok but when I close Form2, I get an error at the above
"Application(Run)" line stating an "External Component has thrown an
exception" How can I continue executing code and accepting events in Form1
after I close Form2
--
Dennis in Houston
Nov 21 '05 #1
5 1358
I cannot see why you are wanting to run from Sub Main

Try using Application.Run(MainForm)
What are you actually trying to do? Create a splash screen or something?
Nov 21 '05 #2
Cheating would be

try

catch ex as exception
finally

but leave the blank after the Catch Ex - then the error doesn't do
anything. However this may cause a slight performance problem.

Where is Sub Main located in the Application? I'd ditch the Application.Run
() - since it will run anyway right?

or below ---

Public MainForm as New Form1

Protected Sub Main_Load (byval sender as system.object, byval e as
system.eventargs) handles mybase.load
MainForm.Show()
End Sub
this should fire as soon as the main window loads - you can repeat the load
anywhere (like in Form1)

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #3
A form by itself cannot run. There must be a message pump for the app
to continue to run, that's what Application.Run.

I doubt that your problem is caused by the Application.Run. When you
get the exception, what does the stack trace show? Put a Try Catch
block around your code and catch the exception and then print out the
stack trace. That should yeild some additional information:

Public MainForm as New Form1
<STAThread()> Public Sub Main()
Try
MainForm.Show()
Application.Run()
Catch ex As Exception
MsgBox(ex.StackTrace)
End Try
End Sub

Nov 21 '05 #4
I have tried that and no I'm not into splash screens. I just want to show a
second Form using .ShowDialog from the first for the user to chose some
options then click OK. However, when the Form I showed using .ShowDialog
closes, the program crashes giving me the error on the Application.Run or the
Application.Run(MainForm) line.

"Crouchie1998" wrote:
I cannot see why you are wanting to run from Sub Main

Try using Application.Run(MainForm)
What are you actually trying to do? Create a splash screen or something?

Nov 21 '05 #5
Thanks. I"ll work with it some more. The Sub Main is in a module set as
the application start-up sub. If I bypass the Sub Main and just set my Form1
as the start-up form, it runs fine and when my Form2 dialog closes, it
continues executing in Form1 at the statement after the Form2.ShowDialog
statement.

"Dustin Brisebois via DotNetMonster.com" wrote:
Cheating would be

try

catch ex as exception
finally

but leave the blank after the Catch Ex - then the error doesn't do
anything. However this may cause a slight performance problem.

Where is Sub Main located in the Application? I'd ditch the Application.Run
() - since it will run anyway right?

or below ---

Public MainForm as New Form1

Protected Sub Main_Load (byval sender as system.object, byval e as
system.eventargs) handles mybase.load
MainForm.Show()
End Sub
this should fire as soon as the main window loads - you can repeat the load
anywhere (like in Form1)

--
Message posted via http://www.dotnetmonster.com

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andi Plotsky | last post by:
I have a subform where I dynamically change the SourceObject dependent upon the User's response to questions on the Main form. My problem is that the scrollbars do not show up on either the Main...
2
by: Krzysztof Karnicki | last post by:
I would like develop Form on my Windows Application, that is going to notify the user, just like Microsoft Office 2003 shows that there are new mail coming. When I use System.Windows.Forms.Form and...
2
by: Sharon | last post by:
I have a Form class that can be open by parent Form or by .NET Remoting command. When the parent Form opens the Form - All fine ! But when the .NET Remoting command is trying to Show the Form, the...
4
by: Grant Schenck | last post by:
I have a C# form application. Once my main window is showing I want to pop-up a login type dialog. What event would I trap to affect this? I tried handling the form load but the main form window...
6
by: John Dann | last post by:
I have a main form and then a secondary form that allows entry of some settings. I want to show the secondary form modally (I guess using ..ShowDialog), but I'd like it shown against the background...
1
by: kenduron | last post by:
Hello together! How would you manage the following termin: I got table "A" and table "B" I have to show most of the fields in "A", an one columm in table "B". But table "B" can have...
4
by: TonyJ | last post by:
Hello! I have a small program that just copy a file and make some checks in main then I just want to inform the user about something by using a MessageBox. I tried to use this in the...
5
by: John Dann | last post by:
Something very simple that I can't spot how to do: I wand to display a msgbox showing some current configuration parameters when my VB2005 program starts up. However, I want the main form to...
2
by: mdejac | last post by:
I was wondering why the background color is not showing up in Mozilla. When I view the page there is a light blue background, when it should be black. Thank you for any help. ...
7
by: =?Utf-8?B?TWF0dA==?= | last post by:
Hi I have an app that runs without a main form, just a notification icon, when the user clicks the icon the form is shown, and when the form is minimized it's hidden. This all works great,...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.