Hi
In a form called FileHandling.cs ,which is called from the main() function, I will
call another form called LicenceKey. My questionn is after calling the Licencekey form I want to close/hide the Filehandling.cs . I have written the following code to do that but its not working. plz help
private void FileHandling_Load(object sender, EventArgs e)
{
string path = @"c:\licence.txt";
if (File.Exists(path))
{
FileHandling.ActiveForm.Close();
Form1 login = new Form1();
this.Hide();
}
else
{
FileStream fs = File.Create(path, 1024);
byte[] info = new UTF8Encoding(true).GetBytes("hi,written");
fs.Write(info, 0, info.Length);
fs.Close();
this.Hide();
LicenceKey lkey = new LicenceKey();
lkey.Show();
}
}
Note: FileHandling.cs is the Parent form
Thanks
Sachi
Loading
Roei BarPosted Aug 3, 2009, 7:29 AM
you can close other forms in MDI, by either putting them as public, and access their "Visible" Property via the main Form.
or you can use Delegates, and raise Event, like :
delegate on form1
event on the Form_Load that will call Form2 Delegate to perform Form Hide/Close
Niradhip ChakrabortyPosted Aug 3, 2009, 7:28 AM
1. http://www.dotnetcurry.com/ShowArticle.aspx?ID=125&AspxAutoDetectCookieSupport=1
2.http://stackoverflow.com/questions/40962/how-do-i-close-a-parent-form-from-child-form-in-windows-forms-2-0
3. http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=49868
sachi vasishtaPosted Aug 3, 2009, 6:44 AM
Nirdhip I want to close/hide the parent form(FileHandling.cs) when I will open LicenceKey.cs form. Not the children forms.
Niradhip ChakrabortyPosted Aug 3, 2009, 4:52 AM
foreach (Form f in this.MdiChildren)
{
f.Close();
}
To close them from some other form, replace 'this' with a reference to the Mdi Parent form.
To open another form, just create an instance of it and call the Show() or ShowDialog() methods on that instance, depending on whether its modal or not.