Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 20th, 2006, 11:03 AM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
Show or hiding forms/modifying control properties ..from different a form..

Hi.
I'm having problems with accessing forms and their properties/functions from different forms, I have a menu (ToolStrip) which has a drop down list for the forms shown, so checking/unchecking the form will hide or show the selected form.
Firstly when hiding/showing my forms they don't keep the data that was inputted because I'm calling new forms to be created (I don't know another way to call a form as an 'MdiChild'. Here's the code I'm using to open the form as a child (from the menu of the parent container).
            if (scriptEditorToolStripMenuItem.Checked == true)
            {
                Form Script = new TFX_Script();
                Script.MdiParent = this;
                Script.Show();
            }
            if (scriptEditorToolStripMenuItem.Checked == false)
            {
                foreach (Form Script in this.MdiChildren)
                {
                    Script.Hide();
                }

            }
TFX_Script is the child form.

This worked well except for two problems. The data inputted into the form (it's controls.. textboxes, checkboxes etc.) will be gone when the new form is created, I don't want that >_<!

The second problem is that obviously the child form can be fully closed within itself via the 'X' button. I don't know how to access the parents menu to change the checkbox (visible or not visible), Also all data will be lost again, I'd rather cancel the close and hide it, while changing the state of the checkbox on the parents menu.

Atm, I'm using a not-so-good work around, when the menu is clicked it checks if the form is opened or not, then changes the checkbox in the submenu (for the form) accordingly.
            foreach (Form Script in this.MdiChildren)
            {
                if (Script.Visible == false)
                {
                    scriptEditorToolStripMenuItem.Checked = false;
                }
                else
                {
                    scriptEditorToolStripMenuItem.Checked = true;
                }
            }
This doesn't look too good since you can see the check (in the menu) flash and it doesn't fix my other problem with loosing the data also.

If you can help me sort this out it will be greatly appreciated!
Thanks~

-cloud- <_<
cloud- is offline   Reply With Quote
Old Oct 24th, 2006, 6:30 PM   #2
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
Sorted~

If someone ever needs to know..

Calling parents functions from child..

ParentForm SomeName = (ParentForm)MdiParent;
SomeName.Function();

..and for hiding/showing the forms, loop through them to check if the form already exists.. if not create a new one..

Sorry for answering my own question <_<;

/Kill thread
cloud- is offline   Reply With Quote
Old Nov 1st, 2006, 12:08 AM   #3
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 237
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
there's an easier way, don't declare your new form in the handler, instead declare it at the top of your class and then just .show or .hide accordingly in the handlers. that way you only have one form throughout the life of the parent instead of creating a brand new one each time the event is raised.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Nov 1st, 2006, 1:33 PM   #4
Iftikhar
Programmer
 
Iftikhar's Avatar
 
Join Date: Oct 2006
Location: London
Posts: 40
Rep Power: 0 Iftikhar is on a distinguished road
Send a message via MSN to Iftikhar
Because you are creating new form by using new keyword so all of your previous data is lost.
You can have private objects of the forms you want to show hide. Before displaying them check the specific object is null or not. If it is null then create a new form with new keyword else just show the form or hide it. In this way you will not loose data. for example
 public class MainForm
{
private TFX_Script o_TFX_Script;

click_function()
{
  if (o_TFX_Script == null)
  {
    o_TFX_Script = new TFX_Script();
    o_TFX_Script.Show();
  }
  else
  {
    o_TFX_Script.Show();
  }
}
}
__________________
Iftikhar Ahmed Khan
For doing an experiment on programmer's mood please visit http://uxisfyp1.brunel.ac.uk/cspgiak
Iftikhar is offline   Reply With Quote
Old Nov 10th, 2006, 10:51 AM   #5
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
That's so much better! Thanks!~
I ran in to trouble with my method, changing the child's properties didn't work as planned, this has fixed all my troubles. ^^
cloud- is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET Timer Form closing issue MBirchmeier C# 4 Nov 21st, 2005 10:00 AM
Show web user control hidden see07 C# 1 Feb 2nd, 2005 10:35 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC