473,703 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open Another form and close itself in vb.net

For example, I create Login form first. When user login, it open the main
form and close the login form itself.
Nov 21 '05 #1
10 33451
"Alex" <Al**@discussio ns.microsoft.co m> schrieb:
For example, I create Login form first. When user login, it open the main
form and close the login form itself.


\\\
Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module
///

In the project properties, select 'Sub Main' as startup object. Place the
code below in a button's 'Click' event handler:

\\\
Dim f2 As New Form2()
f2.Show()
Me.Close()
///

You can exit the application by calling 'Application.Ex itThread'. Take a
look at the 'ApplicationCon text' class too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Why does the following slightly modified code cause an exception to be thrown
on the Application.Run Line?

Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module

In Form1 button 'Click' event handler:

Dim f2 As New Form2()
f2.ShowDialog() Note after return from this Dialog, an exception is thrown.
"Herfried K. Wagner [MVP]" wrote:
"Alex" <Al**@discussio ns.microsoft.co m> schrieb:
For example, I create Login form first. When user login, it open the main
form and close the login form itself.


\\\
Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module
///

In the project properties, select 'Sub Main' as startup object. Place the
code below in a button's 'Click' event handler:

\\\
Dim f2 As New Form2()
f2.Show()
Me.Close()
///

You can exit the application by calling 'Application.Ex itThread'. Take a
look at the 'ApplicationCon text' class too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Dennis,

"Dennis" <De****@discuss ions.microsoft. com> schrieb:
Why does the following slightly modified code cause an exception to be
thrown
on the Application.Run Line?

Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module

In Form1 button 'Click' event handler:

Dim f2 As New Form2()
f2.ShowDialog() Note after return from this Dialog, an exception is
thrown.


I am not able to reproduce that on my machine (.NET 1.1 SP1, Windows XP
Professional SP2). What exception is thrown? Can you post the complete
error message?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Herfried,

What is the deeper reason that you use this code forever.
\\\
Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module
///


(This is a serious question)

Saying it in otherwords what is in your opinion the advantage above the
build VBNet method in a windowform project.

Cor
Nov 21 '05 #5
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
What is the deeper reason that you use this code forever.
\\\
Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module
///


(This is a serious question)

Saying it in otherwords what is in your opinion the advantage above the
build VBNet method in a windowform project.


The built-in possibility of setting the startup form doesn't provide a way
to call 'Application.Ru n' without passing a form to it. In other words, the
'Sub Main's code is generated by the compiler automatically and doesn't give
you the control to do that. The code above does not suffer from the problem
that closing the main form closes the whole application because it's lacking
a message pump after the startup form has been closed.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Herfried,

The only argument I read here is the aspect of clossing the mainform, where
I see no reasons for, but I will not tell direct I disagree about that.

However than has the main really to be the main of the project and than
should there not be any form call from another place in my opinion. I think
that any tree structure inside a form node than is not right.

The load event in a form does so nice everything before the showing of the
form. Your arguments about this looks for me more something of behaviour
from an old VB6 programmer who is afraid that they will change that nice
behaviour again (Or maybe it was already like that, I don't remember it me
anymore).

However just my thought of course.
And feel free to do it your way.

Cor
Nov 21 '05 #7
Cor,

"Cor Ligthert" <no************ @planet.nl> schrieb:
The only argument I read here is the aspect of clossing the mainform,
where I see no reasons for, but I will not tell direct I disagree about
that.

However than has the main really to be the main of the project and than
should there not be any form call from another place in my opinion. I
think that any tree structure inside a form node than is not right.


It seems to me that you didn't get the point of what I am saying.

The application is started.
'Form1' is shown.
'Form1' is closed.
'Form2' is shown.
'Form2' is closed.
...
The application terminates.

How would you do that without a custom 'Sub Main' and without using ugly
'ShowDialog' hacks?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Herfried,

It seems to me that you didn't get the point of what I am saying.

The application is started.
'Form1' is shown.
'Form1' is closed.
'Form2' is shown.
'Form2' is closed.
...
The application terminates.


When this is consequently done, I said that I agreed (however than no shows
inside a form).

:-)

Cor
Nov 21 '05 #9
If I try a simple example it seems to work OK. However, my application is
too complex to post here. I did find out that if I delete a line of Code I
had, "Application.En ableVisualStyle s()" in my sub main, my application works
ok but with this line of code in sub main, it throws an exception when Form2
closes. It does seem to work OK with a simple example however. Maybe it's
one of the controls that I have on my Form1 such as splitter bar, panel,
toolbar, listbox, treeview, etc. Anyway, I'll live with out VisualStyles for
now until I get time to see exactly what's casuing the error.

Sub Main
Application.Ena bleVisualStyles
Form1.Show
Application.Run ()
end Sub
"Herfried K. Wagner [MVP]" wrote:
Dennis,

"Dennis" <De****@discuss ions.microsoft. com> schrieb:
Why does the following slightly modified code cause an exception to be
thrown
on the Application.Run Line?

Public Module Program
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run ()
End Sub
End Module

In Form1 button 'Click' event handler:

Dim f2 As New Form2()
f2.ShowDialog() Note after return from this Dialog, an exception is
thrown.


I am not able to reproduce that on my machine (.NET 1.1 SP1, Windows XP
Professional SP2). What exception is thrown? Can you post the complete
error message?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #10

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

Similar topics

4
10283
by: KS | last post by:
Is it possible to write a javascript that makes a popup window when someone click on buttons/href on my page and close itself when the new page is about to get loaded? I want to prevent the user from clicking anything else on my page while the request is getting a new page. The popup window must lock the focus. I use frames i can not just disable all the buttons an href in different frames.
1
2100
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this: foreach(MyForm form in AllMyForms){ form.Close(); } Application.Exit(); The OnClosing method is overridden in MyForm. If the user has made changes to his form, this method asks him if he'd like to: a) save his changes b) forget changes...
1
4222
by: Martin Douglas | last post by:
Hey guys, maybe someone can help me with some MDI issues I have. A co-worker asked me a very simple question, one that I blew off as trivial, and it has become a time-consuming issue. Simply put, there is an MDIForm and a child form. The MDIForm does the usual from within its constructor... this.IsMdiContainer = true; Form2 frm = new Form2();
6
6825
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2| .Open query1 3| .Close 4| .Open query2 5| End With
3
10572
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The other one is Next button which i created to open another form "frmSummary" which displays back the records submitted. (i used the wizard to open form and find specific records to display. All these works superb until a review by users where they...
5
9275
by: Andrew Morton | last post by:
Is it possible to make a form deactivate itself without minimizing it? I have written a small utility which copies selected files from CDs (hundreds of them). I put a CD in the tray and click a button on the form to tell it the next CD is ready for it to process. Each CD takes a few minutes to copy, and the form has a textbox at which I glance to see the progress. I have the form sending itself to the back, but it would be nice if it...
14
25052
by: keri | last post by:
Hi, Simple version of the question..... How do I use the where clause of the open form command to show an account with a matching ID to be displayed when the form is opened? Eg. I select a record on a continuous form and click and edit button. The button runs the open form code. I want the APPID of the current record on the continous form to match the APPID of the record viewed
4
1803
by: sheldonlg | last post by:
Does anyone know how to open a window and have it close by itself? You may ask why, but here it is. I want to have it open (a php script), run that script, and then close itself. I have an application that is a huge AJAX framework app. There appears to be some interaction between that and the mail sending software I have. I want to send email with a file attached. The software I am using for that is htmlMimeMail5 (php5). Since I...
6
3691
by: dotnetnovice | last post by:
Hi everybody. I need some help in c# forms problem which is i have three forms naming main form,form1 & form2. main form is the mdiparent of both form1 and form2. i also have a toolstrip in my main form which includes option close current frm and close all. what i need is when i click the close current form option the form opened state(either form1 or form2) close down. suppose currently form 2 is currently open in the main form and i...
29
30015
sueb
by: sueb | last post by:
I have a little form that I want to: 1. accept a new primary key (chart number) (this is the only field on the form), 2. add a new record with this primary key, 3. open the main form, and 4. close itself So far, it does 1 through 3, but doesn't do 4, and also gives me an error, saying that there's an operator missing on line 12 of the following code: Private Sub ChartNum_Exit(Cancel As Integer)
0
8750
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8662
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9246
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8961
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7856
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5922
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4680
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3115
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
3
2058
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.