![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 1
| Updating forms |
| geek74 is offline | |
| | #2 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| Geek74, I'm confused as to how your question relates to this thread. Anyway, you've not given much details of your project, therefore I will assume that your main form class is called Form1, and that your form which you want to close is called Form2. First thing to do is create the event FormClosing in your Form2: Code: protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
}
Code: public void UpdateData()
{
// do update stuff here
}
Code: protected override void OnFormClosing(FormClosingEventArgs e)
{
((Form1)this.Parent).UpdateData();
base.OnFormClosing(e);
}
|
| theoobe is offline | |
| | #3 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,362
| Posts moved to a new thread.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #4 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,122
| If the subform is a dialog (modal form) then you could do this: Form1 - Main form Form2 - Sub form (dialog) Code: //This code is called when you want to open the sub form
//Create the sub form
var Dialog = new Form2();
//Show the sub form
if(Dialog.ShowDialog() == DialogResult.Ok)
{
//If the user pressed Ok, update the data
//(don't update if he pressed Cancel or closed it)
UpdateData();
}
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #5 | |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| Quote:
Code: using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Form2 f2;
public Form1()
{
InitializeComponent();
this.f2 = new Form2();
this.f2.FormClosing += new FormClosingEventHandler(this.Form2Closing);
this.f2.Show();
}
private void Form2Closing(object sender, FormClosingEventArgs e)
{
// do update stuff here
}
}
}
| |
| theoobe is offline | |
| | #6 |
| Registered User Join Date: Oct 2009
Posts: 1
| Is there a way to add the OnformClosing event through th UI instead of writing the code |
| DrGuitar is offline | |
| | #7 |
| Registered User Join Date: Jun 2008 Location: RING 0
Posts: 462
| Open the form in editor. Look at your properties window, click on the lighting bolt (events), find your event, type an event name, select a pre-existing one, or double click to have it generate one for you. Again I would handle updates how magos suggested. Handle input verification on the form. |
| valaris is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Good introduction to Windows Forms? | jcafaro10 | C# Programming | 1 | 05-19-2009 06:11 PM |
| insert differnt forms in a single form under different tabs? and a textBox question | arian | C# Programming | 2 | 04-02-2009 04:40 AM |
| Httpd forms with? | |HBO| | Networking/Device Communication | 1 | 02-22-2008 11:45 PM |
| C# Game using Forms | ejohns85 | C# Programming | 1 | 12-16-2006 05:35 PM |
| Which one :MFC, Win32, Windows Forms (.Net)? | Robert_Sitter | Windows Programming | 6 | 11-17-2005 06:15 AM |