dotnetspider.com


 


TutorialsForumResourcesReviewsJobsInterviewVideosCommunitiesProjectsTraining

Subscribe to Subscribers


Online MembersRavindran
Ajatshatru Upadhyay
abhishek
chirag jaguwala
More...




Forums » .NET » .NET »

closing form....


Posted Date: 29 Jun 2005      Posted By:: muthukrishnan     Member Level: Silver    Member Rank: 0     Points: 2   Responses: 8



Hi friends,

Thanks in advance for your help...

abt my problem is....

i have an login form..after i login i moved to anoter form tat time my login form should be closed...

but if closed my login form the next form(where i moved),also closed...

i just want to close my login after i login correctly...

how to i do that?

my exampel code here...

Dim register As New Regis
register.Show()
Me.close()(this is login form)...

how do i close only login form...

waiting for your valuable information...

from,
muthu





Responses

#24364    Author:       Member Level: Gold      Member Rank: 0     Date: 30/Jun/2005   Rating: 2 out of 52 out of 5     Points: 2

Hi Muthu!
I don't think you can close the main form when the Child form is alive.
Try it. If you are not done, follow this.

Hide the Form1 while activating the Form2.
When you close the Form2, You must explicitly close the Form1.

I don't know how feasible this solution be but it serves your problem.
The overheads in this approach are
1. You have to maintain the reference of the Form1 in some global area (like static variable)
2. Though Form1 is hidden, it will be in memory till you close Form2.



#24369    Author:       Member Level: Silver      Member Rank: 0     Date: 30/Jun/2005   Rating: 2 out of 52 out of 5     Points: 2

Try using window parent/child relation using a script.

Here it goes

Call a window close function on click of login button as follows.

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
LoginButton1.Attributes.Add("OnClick","openWindow('child.aspx?login=true');");
}

and write the following script code in the login.aspx

<script language="javascript">
function openWindow(url)
{
window.open(url);
}
</script>

in the child.aspx i.e. the page where you want to redirect the user after login, write a small script on body load as follows.

<html>
<head>
<title>Successfully Logged in!!!</title>
<script language="javascript">
function MaximiseWindow()
{
x = screen.width ; y = screen.height
window.resizeTo(x,y);
window.moveTo(0,0);
window.opener.close();
}
</script>
</head>
<body MS_POSITIONING="GridLayout" onload="javascript:MaximiseWindow();">

<form id="Form1" method="post" runat="server">
You are successfully loogged in....

</form>

</body>
</html>

But you are likely to get a warning message in IE , to check whether you want to close the window.
If you want to avoid this , you can open the login form also in a window.

Hope this helps you..

Cheers
Rags



#24372    Author:       Member Level: Silver      Member Rank: 0     Date: 30/Jun/2005   Rating: 2 out of 52 out of 5     Points: 2

Hi!

Use Thread to open another Form!!! Check this sample code...



private void btnLogin_Click(object sender, System.EventArgs e)
{
this.Close();
Thread th = new Thread(new ThreadStart(myForm));
th.Start();
}

private void myForm()
{
Form2 f = new Form2();
f.ShowDialog();
}



Regards,
Zabi.






#27097    Author:       Member Level: Bronze      Member Rank: 0     Date: 03/Aug/2005   Rating: 2 out of 52 out of 5     Points: 2

Hi Muthu
Try This....
1) create a Object for Form 2
2) Activate Form2
3) Hide the Parent Form
For an Example
Here Form 1 is Parent Page (Login Page ) and Form 2 is Next Page.

private void button1_Click(object sender, System.EventArgs e)
{
Form f2=new Form2();
f2.Show(); // This Activates Child Form
this.Hide(); // This Hides Parent Form (Login Form)
}
Please forward ur Feedback..............



#29295    Author:       Member Level: Silver      Member Rank: 0     Date: 01/Sep/2005   Rating: 2 out of 52 out of 5     Points: 2

hi

try using

window.opener.close();
in the child form

regards
Arthy



#50868    Author:       Member Level: Bronze      Member Rank: 0     Date: 02/May/2006   Rating: 2 out of 52 out of 5     Points: 2

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Loginfrm = new Login();
frm.ShowDialog();
//make boolean property IsCloseAll and default it to true
//So that if user hit cross he can go out
//and dont forget it to set it false at the event where user want
// to close login form and come to MainForm
if (frm.IsCloseAll != true)
{
Application.Run(new MainForm());
}
}



#142261    Author:       Member Level: Silver      Member Rank: 0     Date: 06/Aug/2007   Rating: 2 out of 52 out of 5     Points: 2

Hey use this for c#
......................................................................................................................................................................
.......................................................................................................................................................................
........................................................................................................................................................................



[code in programe.cs file]

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
}

[/code in programe.cs file]

[code in Login.cs file]

private void login_click(object sender, EventArgs e)
{
this.close(); //"this" is used for login form which would be closed

// include ref : system.Thread;

Thread th = new Thread (new ThreadStart(myform));
th.start;

}

Private void myform()
{
frmMDI f = new frmMDI();
// frmMDI is the next form which would be open
f.showdialog();
}
[/code in Login.cs file]




#178053    Author:       Member Level: Silver      Member Rank: 0     Date: 10/Jan/2008   Rating: 2 out of 52 out of 5     Points: 2

For Each ChildForm As Form In Me.MdiChildren
ChildForm.Close()
Next




Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Previous : Is there any expert to solve this?
Return to Discussion Forum
Post New Message
Category: .NET

My Profile

Active Members
TodayLast 7 Daysmore...


Awards & Gifts


Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds



    About Us    Trademark Disclaimer    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.