PDA

View Full Version : [SOLVED] C#/object orientation question



beno1990
October 24th, 2008, 12:11 AM
Hello! I'm a programmer coming from a mostly procedural programming background but I'm learning C# as I go in MonoDevelop.

But there's one thing I can't seem to get and it's bugging me, is if I want to control a window other than the active window. For example, a dialog box popup which asks you to confirm that you want to continue. If I want the dialog box *and* the parent window to close when I click ok, I can't seem to access the parent window, eg:



protected virtual void btnOk_clicked (object sender, System.EventArgs e)
{
MainWindow.Destroy(); //doesn't work
this.Destroy(); //works fine
}


Is there a way to control another class like that which I don't know of?

Thanks for reading this.

jimi_hendrix
October 24th, 2008, 12:49 AM
this closes both (and ends the app)


private void button1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("hello") == DialogResult.OK)
{
Application.Exit();
}

}

beno1990
October 24th, 2008, 12:56 AM
Thanks, but I'm not trying to close the application. I still want a dialog box to show with the results of the application's run and give the option of starting from scratch.

jimi_hendrix
October 24th, 2008, 01:26 AM
if (MessageBox.Show("hello") == DialogResult.OK)
{
this.Close();
loadprogram(); //user defined method to load new forum that you make
}

this will close the current forum and then you can load your starting screen with loadprogram method