johnwalden869050
asked on
Having trouble accessing a MDI Parent from a child when using a cast.
Hi!
I am designing a tabbed web browser using C# and have run into a few problems. If anyone out there can help I would be much obliged!
My problem is accessing common fields on the MDI Parent from the child. Basically I want to update the address bar (and other fields) on the MDI Parent when the child form's "webbrowser.navigated" event fires. The code I am using is...
private void webMainBrowser_Navigated(o bject sender, WebBrowserNavigatedEventAr gs e)
{
frmMain MainForm = (frmMain)this.MdiParent;
MainForm.cmbAddress.Text = this.webMainBrowser.Url.To String();
}
There are no errors being thrown up in my code but nothing is happening either! Help!
Regards
John
PS Hate to state the obvious but I am a newbie!
I am designing a tabbed web browser using C# and have run into a few problems. If anyone out there can help I would be much obliged!
My problem is accessing common fields on the MDI Parent from the child. Basically I want to update the address bar (and other fields) on the MDI Parent when the child form's "webbrowser.navigated" event fires. The code I am using is...
private void webMainBrowser_Navigated(o
{
frmMain MainForm = (frmMain)this.MdiParent;
MainForm.cmbAddress.Text = this.webMainBrowser.Url.To
}
There are no errors being thrown up in my code but nothing is happening either! Help!
Regards
John
PS Hate to state the obvious but I am a newbie!
ASKER
Hi!
Thanks for your interest. I have tried as you have suggested and got a compiler error...
'frmMain' is a 'type' but is used like a 'variable'
Any ideas?
Thanks again
John
Thanks for your interest. I have tried as you have suggested and got a compiler error...
'frmMain' is a 'type' but is used like a 'variable'
Any ideas?
Thanks again
John
I don't see any obvious reasons why this wouldn't work...
This worked in a simple project for me:
public partial class frmMain : Form
{
private void frmMain_Load(object sender, EventArgs e)
{
Form9 f9 = new Form9();
f9.MdiParent = this;
f9.Show();
}
}
public partial class Form9 : Form
{
private void button1_Click(object sender, EventArgs e)
{
frmMain MainForm = (frmMain)this.MdiParent;
MainForm.textBox1.Text = "Hello world!";
}
}
This worked in a simple project for me:
public partial class frmMain : Form
{
private void frmMain_Load(object sender, EventArgs e)
{
Form9 f9 = new Form9();
f9.MdiParent = this;
f9.Show();
}
}
public partial class Form9 : Form
{
private void button1_Click(object sender, EventArgs e)
{
frmMain MainForm = (frmMain)this.MdiParent;
MainForm.textBox1.Text = "Hello world!";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dean,
Thanks for your help. I must be missing something further up the line.
All the best,
John
Thanks for your help. I must be missing something further up the line.
All the best,
John
frmMain MainForm = frmMain()
MainForm = (frmMain)this.MdiParent;
also put try catch blocks to trap any errors...