473,382 Members | 1,441 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,382 software developers and data experts.

moving from one form to another and closing the previous one

hello!
i need help with this issue.i have created a form and have designed a button to take me to another form.after the second form loads,i want to close the first form without affecting the second.kindly help me
Sep 10 '07 #1
5 1199
hello!
i need help with this issue.i have created a form and have designed a button to take me to another form.after the second form loads,i want to close the first form without affecting the second.kindly help me

Try this code:

in your button: put this code..
Expand|Select|Wrap|Line Numbers
  1. form2.show();
  2. form1.close();
  3.  
form2 is the second form
Sep 11 '07 #2
Try this code:

in your button: put this code..

form2.show();
form1.close();

form2 is the second form
this is isnt working for me.because i ve declared an instance of the second form in the first and invoke it from there.so when i close the first one,the second one also closes.am desperate.please help
Sep 11 '07 #3
Frinavale
9,735 Expert Mod 8TB
this is isnt working for me.because i ve declared an instance of the second form in the first and invoke it from there.so when i close the first one,the second one also closes.am desperate.please help
Don't use Form1.close()...try Form1.hide() instead.

The reason is because the Close() method closes the form (destroys it) and since you've declared your Form2 inside Form1 this destroys the object you're trying to work with too..

See MSDN for more information on
the Form.Close() method
and
the Form.Hide() method


Cheers!

-Frinny
Sep 11 '07 #4
Plater
7,872 Expert 4TB
What I would do is create a STATIC class with public static member for each of your forms:

Expand|Select|Wrap|Line Numbers
  1. public static class myManager
  2. {
  3.    public static Form1 myform1;
  4.    public static Form2 myform2;
  5.  
  6.    public static void CreateShowForm1()
  7.    {
  8.       if(myform1!=null)
  9.       {
  10.          myform1.Show();
  11.       }
  12.       else
  13.       {
  14.          myform1=new Form1();
  15.          myform1.Show();
  16.       }
  17.    }
  18.    public static void CreateShowForm2()
  19.    {
  20.       if(myform2!=null)
  21.       {
  22.          myform2.Show();
  23.       }
  24.       else
  25.       {
  26.          myform2=new Form2();
  27.          myform2.Show();
  28.       }
  29.    }
  30.    public static void DestroyForm1()
  31.    {
  32.       if(myform1!=null)
  33.       {
  34.          myform1.Close();
  35.          myform1.Dispose();
  36.          myform1=null;
  37.       }
  38.    }
  39.    public static void DestroyForm2()
  40.    {
  41.       if(myform2!=null)
  42.       {
  43.          myform2.Close();
  44.          myform2.Dispose();
  45.          myform2=null;
  46.       }
  47.    }
  48. }
  49.  
Now you can call these methods from anywhere. If you need special constructors for your forms, you can just overload these functions to also take parameters that you can pass in to the constructors.
Sep 11 '07 #5
Thanks a lot.am glad i started this discussion.million thanks to you.i ll try it out!
thank u! ;-)
Sep 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I...
2
by: Curtis Justus | last post by:
Hi, I currently have a control that is on a form and I want to pass that exact instance of the control to another form (a child form that appears on a button click). The control has state,...
3
by: Corey | last post by:
Dear All, I know there's a simple solution to what I want to do, but for the life of me I can't figure it out. I think it's because I've been corrupted by too long with VB6..... :) Any way...
5
by: Dylan Parry | last post by:
Hi, I'm trying to upload some files via a form, and I have managed so far to save the files on the server in a temporary directory using: HttpPostedFile.SaveAs(string filename); This is a...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
3
by: Gilberto | last post by:
Hello This must be pretty simple but i havent found the way to do it. I have a form with a button that opens another form on click. WHAT command and WHERE do i need to CLOSE the previous form...
3
by: godhulirbalaka | last post by:
Dear Sir/Madam, I am new vb 6.0 user. I am developing Shop Management Program. I have a main form with buttons and menus. when i click any button then respective form is open. I want to set a...
5
by: Neil | last post by:
"lyle" <lyle.fairfield@gmail.comwrote in message news:48c3dde7-07bd-48b8-91c3-e157b703f92b@f3g2000hsg.googlegroups.com... Question for you. I'm doing something similar, only, instead of opening...
11
by: dizzydangler | last post by:
Hi, all! I'm a new user, looking to get some help on a form problem in MS Access 2007 I haven't been able to crack. I've built a form that prompts users to enter new record data, then click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.