Employers - Post Free Jobs
Forum guidelines
AuthorQuestion
how to move one window form to another window form
Posted on: 19 Nov 2009

hi
i hava login page form(Login),when i click on login button i want to move another form(Users) and i want to close Login form.
i wrote this code in button click
UsersForm obj = new userForm();
obj.show();
this.close();//Login page close
 once i call this.close() method both forms are closed ..
plz give me solution....

AuthorReply
Re: how to move one window form to another window form
Posted on: 19 Nov 2009  
You can use this code for close current window

<script language=javascript>
function closer()
{
this.close();
}
</script>

<form name=xcv>
<input type=button onClick="closer()" value="click to close">
</form>


More Example might be help using Javascript.

Please check my answer if you help.....

Thanks ....Lalit.

Re: how to move one window form to another window form
Posted on: 19 Nov 2009  
Friend,


Use this method.



        private void button1_Click(object sender, EventArgs e)
        {
 
            System.Threading.Thread mythread = new System.Threading.Thread(new System.Threading.ThreadStart(OpenNewFrom));

            mythread.Start();

            this.Close();

        }
        public static void OpenNewFrom()
        {

            Application.Run(new UsersForm());//Create an instance of your new form. No need to call show method.

        }


If this helps you, please do not forget to mark this answer as accepted.




Nilanka Dharmadasa

Re: how to move one window form to another window form
Posted on: 20 Nov 2009  
thanks niki
Re: how to move one window form to another window form
Posted on: 20 Nov 2009  
Hey Jeevan,

Pls mark my answer as ACCEPTED if it helped you. It HELPS me.... :)

Nilanka Dharmadasa

Re: how to move one window form to another window form
Posted on: 15 Mar 2012  
thanks Nilanka..
it is working properly.
but can u explain me following line..

System.Threading.

 Thread mythread = new System.Threading.Thread(new System.Threading.ThreadStart(OpenNewFrom));




Re: how to move one window form to another window form
Posted on: 15 Mar 2012  
It's creating a new thread which when started - with mythread.Start() - will call the OpenNewFrom method.

This is necesssary because when this.Close() is called, the current user interface thread will terminate.

Re: how to move one window form to another window form
Posted on: 16 Mar 2012  
Thanks Vulpes for ur reply..!
Re: how to move one window form to another window form
Posted on: 22 Apr 2012  
Hey thanks nilanka....this code was very helpful....Can you please tell how can I pass values from one windows form to another using threads.

Data db = new Data();
                     db._textBox = name;
                     db._textBox1 = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                            db._index = trainingImages.LastIndexOf(result) + 1;
                            db.Show();
                            stop_capture();
                            button1.Enabled = true;

I need to pass these values using threads...

Re: how to move one window form to another window form
Posted on: 22 Apr 2012  
I do not understand why a separate thread is required for this.

Also, Application.Run will create a new message loop and that is not necessary.

Please clarify one thing for me. Do you need to show the login form only once or do you need to allow the user to logout and then login  again? If the former; if you need to show the login just once; then a good solution is to show the login form at the beinning of the program, in the Program class in the Program.cs file.

Perhaps the only thing you need to do differently in the code you had originally is to use ShowDialog instead of Show.

If you want the login form ot be modeless instead of modal, then a solution that I often use is to show and hide the other form; the login form instead of creating a new instance every time.

Actually, now that I think about it, I think the only problem with your original code is probably that you have the "this.Close()" in the wrong place. You need to have it in the Login form and you probably do not.

Please, let us first understand what you need to do before we try to suggest solutions. I think the requiremetns are not defined welll enough.

Thinking is a feeling; pleasant for some and unpleasant for others.
Re: how to move one window form to another window form
Posted on: 22 Apr 2012  
Ooooops, sorry; I did not notice that this thread is more than a month old.

Kapil, go ahead and create and create a new discussion for your question.

Thinking is a feeling; pleasant for some and unpleasant for others.
Re: how to move one window form to another window form
Posted on: 12 Jun 2012  
Thankyou Very Much

That was really very Helpfulll.


SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.