473,662 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WinForms Closing problem

Hi

I am facing a problem. I've made an application in which two forms are
there. One if Login form and another is main form. The problem is that,
after getting authenticated from the database the main form is opened. But
the login form is not getting closed. I am using the following code:

It is in the load of the main form.
this.ParentForm .Close();

Giving some error.

Regards

Tarun Mangla


Nov 16 '05 #1
5 8196
Hi,
One option is to hide the login form (after successful logon) and show the
main form using ShowDialog() method (assuming logon form is the startup
form).
Alternative is to show the logon and main forms indepenantly (from Main()).
That is, show the logon form using ShowDialog and based on the dialog result
(eg: DialogResult.OK for successful logon), close the logon form and show
the main form using Application.Run ().
"Tarun Mangla" <ta**********@d rydentech.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
Hi

I am facing a problem. I've made an application in which two forms are
there. One if Login form and another is main form. The problem is that,
after getting authenticated from the database the main form is opened. But
the login form is not getting closed. I am using the following code:

It is in the load of the main form.
this.ParentForm .Close();

Giving some error.

Regards

Tarun Mangla



Nov 16 '05 #2
Hi Tarun
You shouldn't make the logon form the parent form as when you do so . you
will not be able to close the logon form ( the parent) and leave the main
form ( the child) .
One thing you can do; however, is to make the parent form the main form (
it is the one that is passed as a pram to the application.run () function .
Then , on the load event handler of the main form you hide it and open
the logon form
this.Hide() // or this.Visible = false ; then open your login
from as dialog
then get the result from the login form in a dialogResult Object ( in the
main form).
You can read about DialogResult on this link

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwind owsformsdialogr esultclasstopic .asp
If the result shows that the user is authenticated , then close the login
and make the main visible, if not however , you can do whatever action you
want event close the application completely , display error message or
whatever action that match your requirements
hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3
Shiva wrote:
One option is to hide the login form (after successful logon) and show the
main form using ShowDialog() method (assuming logon form is the startup
form).
Alternative is to show the logon and main forms indepenantly (from Main()). That is, show the logon form using ShowDialog and based on the dialog result (eg: DialogResult.OK for successful logon), close the logon form and show
the main form using Application.Run ().
Usually, I open login views as Modal Dialogs im my main forms
Loaded-Eventhandler:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
LoginView login = new LoginView();
login.ShowDialo g(this);
// Do somethin to check if login was successful,
// maybe quit if it wasn't...
}

Thus, the login dialog will be closed automatically before the main view is
opened.

"Tarun Mangla" <ta**********@d rydentech.com> wrote in message
news:e7******** ******@TK2MSFTN GP09.phx.gbl...
Hi

I am facing a problem. I've made an application in which two forms are
there. One if Login form and another is main form. The problem is that,
after getting authenticated from the database the main form is opened. But the login form is not getting closed. I am using the following code:

It is in the load of the main form.
this.ParentForm .Close();

Giving some error.


Exactly what error do you encounter ?
Nov 16 '05 #4
Hi

When I try to hide the main form on the load event, it is not hiding at
all. I don;t know why. I am just sending you the code....

Lets suppose Form1 is the main form and Form2 is the login form and on
the load of form1 I've writtent the code below:

private void Form1_Load(obje ct sender, System.EventArg s e)

{

this.Hide();

Form2 frm2=new Form2(this);

frm2.Show();

}
But the main form is not hiding. When I run this application both the forms
appears on the screen.

Waiting for your reply.

Regards

Tarun Mangla

"Mohamoss" <mo************ @egdsc.microsof t.com> wrote in message
news:EG******** *****@cpmsftngx a06.phx.gbl...
Hi Tarun
You shouldn't make the logon form the parent form as when you do so . you
will not be able to close the logon form ( the parent) and leave the main
form ( the child) .
One thing you can do; however, is to make the parent form the main form (
it is the one that is passed as a pram to the application.run () function .
Then , on the load event handler of the main form you hide it and open
the logon form
this.Hide() // or this.Visible = false ; then open your login
from as dialog
then get the result from the login form in a dialogResult Object ( in the
main form).
You can read about DialogResult on this link

http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfsystemwind owsformsdialogr esultclasstopic .asp
If the result shows that the user is authenticated , then close the login
and make the main visible, if not however , you can do whatever action you
want event close the application completely , display error message or
whatever action that match your requirements
hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #5
Hi!

Tarun Mangla wrote:
[...snip...]
When I try to hide the main form on the load event, it is not hiding at
all. I don;t know why. I am just sending you the code....

Lets suppose Form1 is the main form and Form2 is the login form and on
the load of form1 I've writtent the code below:

[...snip...]

My last application with a login dialog I coded like this (Form1 is the main
form, Form2 the login form class):

private void Form1_Load(obje ct sender, System.EventArg s e)
{
while (this.login() == false) {};
// whatever...
}

private bool login()
{
Form2 loginDialog = new Form2();
loginDialog.Sho wDialog(this);
// get credentials from login dialog
// check if credentials are valid, return false otherwise
// login to the database, return true if login succeeds, false otherwise
}

My main form does not show until the program returns from login()...
Nov 16 '05 #6

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

Similar topics

6
2948
by: Lecture Snoddddgrass | last post by:
Greetings, Can anyone recommend a good 3rd party docking windows component for WinForms? I'm looking for something that allows windows to not only be docked but to "popout", much like the Solution Explorer or Toolbox in Visual Studio.NET. For my last project, I used the SyncFusion component for docking windows, but my experience is that SyncFusion is buggy. I'd prefer to use a different vendor for this project. Any advice? Thanks,
10
2402
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ComboBox.SelectedValue = db_value; If the db_value was not included in the ComboBox value list the ComboBox.SelectedIndex used to return -1, Now the very same code is
22
8825
by: Charles Law | last post by:
Could someone please explain to me, in words of one syllable or less, how I get the Validating event to fire for a form. I have a form with one text box, and two buttons: OK and Cancel. I have the OK button set as the AcceptButton and the Cancel button as the .... well, you've guessed it. I click OK and the form closes, without going to the Form1_Validating event. I could validate in the Click event of the OK button, but I can't...
0
925
by: guy | last post by:
Two of us are working on a Winforms solution (5 projects) and are using VSS, and VB.NET 2003 with one form, regularly on closing it in design mode, or sometimes on checking it in, Sourcesafe prompts for to do a check out for edit even though an edit is not required. it will then not allow a check out Cancel. If the checkout is allowed then most of the controls, primarily those on tab pages or panels. drop off the form. The controls still...
5
4078
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in both projects. Both controls(dlls) have been signed using SN.exe and I've set up the appropriate .Net assembly permissions using those Strong Names The DLL's have been copied to the /bin directory in both web virtual directories.
2
2078
by: Steve Smith | last post by:
I have written an application that launches approximately 150 threads with Thread.ThreadStart() Each thread uses CDO 1.21 to logon to a different Exchange mailbox and send/receive a number of mail messages, reporting back to the UI thread through the use of a Queue object. When all messages that are expected have been received, each thread sends a final update to the UI and the method should exit, which should terminate the thread. ...
23
4520
by: raylopez99 | last post by:
Here I am learning WinForms and two months into it I learn there's a WPF API that is coming out. Is this WPF out yet, and is it a threat to WinForms, in the sense that all the library routines I memorize and/ or familiarize myself in WinForms will disappear in WPF? I did note in one early version of C#, the non-generic "ArrayList" was replaced by the generic and template <based List, but that kind of change is not a big deal. If WPF...
10
2013
by: Descartes | last post by:
Dear All, Coming from another development environment, it appears that I bang my head in the wall on very basic matters, so I hope you can give me a push in the right direction. The application that I work on will consist of - a mainform with a usual menu and toolbar and not much more. - a number of modal data editing forms with various edit controls, an OK button and a Cancel button
2
4226
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
I am (still) relatively new to Windows applications, most of my experience has been Web based, and I am confused about what exactly happens when the Main() method is called and how to manipulate forms opening & closing. An example of this issue is as follows. I have a logon form open as the first thing. The main functional form opens when a user has successfully logged on. From the main form, a user should be able to logout which will...
0
8432
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
8633
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
7365
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...
1
6185
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
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
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
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.