Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2006

Tip: Looking for answers? Try searching our database.

MDI one Child instance.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
scole954387@gmail.com - 28 Sep 2006 04:13 GMT
Hi,

I'm creating a MDI application and running into the common problem of
more than one instance of the child form.   I've read several articles
and postings on the Singleton approach, but I can't get it to work.

What I have:

One form with linklabels and another form with a webbrowser.  When the
linklabel is clicked the webbrowser navigates to the url.  The problem
is each time a linklabel is clicked a new webbrowser form opens.

I'm trying to have the one webbrowser form update to the new url with
each click of a linklabel rather than having multiple webbrowser forms
opening.

Do anyone have any idea on how to do this.  Keep in mind that I am very
new to visual studio and c# programming. Example code is best.

Thanks a bunch,
S. Cole
Steven Nagy - 28 Sep 2006 07:32 GMT
Hi

Sure. Singleton is definately the right approach.
Create a form level declaration of your Form in the parent container
form.
When the link label is clicked, have it check first if the form
instance is null. If it is, then initialise it. Then simply call the
usual mdi parent stuff and show the form.

Eg.
private MyForm as SomeForm
void MyLabel_OnClick(blah blah blah) {
if (MyForm == null) {
  MyForm = new SomeForm();
  // whatever else needs declaring, like setting form parent.
}
MyForm.Show();
}
scole954387@gmail.com - 28 Sep 2006 13:43 GMT
Thanks for the information, but I can't get it to work.

main form - parent mdi
form 1 - link labels
form 2 - webbrowser

My code...
private void lnkGoogle_LinkClicked(object sender,
LinkLabelLinkClickedEventArgs e)
       {
           if (frmContentDisplay == null)
           {
               frmContentDisplay objChildContentDisplay = new
frmContentDisplay();
               objChildContentDisplay.MdiParent = this;
           }
           objChildContentDisplay.Show();
           objChildContentDisplay.LoadURL("http://www.google.com");

       }

and I get the following errors...

Error    1 'CDV_My_Agent.frmContentDisplay' is a 'type' but is used like a
'variable'
Error    2    The name 'objChildContentDisplay' does not exist in the current
context
Error    3    The name 'objChildContentDisplay' does not exist in the current
context

The form is initially loaded by the main mdi window with...

// Show ContentDisplay window on Startup
            frmContentDisplay objChildContentDisplay = new
frmContentDisplay();
            objChildContentDisplay.MdiParent = this;
            objChildContentDisplay.Show();

//objChildContentDisplay.LoadURL("http://www.anything.com");

> Hi
>
[quoted text clipped - 14 lines]
>  MyForm.Show();
> }
Steven Nagy - 28 Sep 2006 21:20 GMT
Try this:

frmContentDisplay objChildContentDisplay;

LinkLabelLinkClickedEventArgs e)
       {
           if (objChildContentDisplay==null)
           {
               frmContentDisplay objChildContentDisplay = new
frmContentDisplay();
               objChildContentDisplay.MdiParent = this;
           }
           objChildContentDisplay.Show();
           objChildContentDisplay.LoadURL("http://www.google.com");

       }
S. Cole - 29 Sep 2006 01:55 GMT
Hey,

Thanks for the help.  Here's the errors received...

Error    1    The name 'objChildContentDisplay' does not exist in the current
context
Error    2    The name 'objChildContentDisplay' does not exist in the current
context
Error    3    The name 'objChildContentDisplay' does not exist in the current
context

I'm assuming that this is happening because there's no such thing as
objChildContentDisplay until the frmContentDisplay
objChildContentDisplay = new frmContentDisplay(); is parsed. And I'm
assuming that this is not getting parsed because of the
objChildContentDisplay==null statement.  Any ideas?

I have the parent form opening the ContentDisplay form (webbrowser
form) under the _Load function.  Should I have the linklabel child form
open it instead?

Thanks,
S. Cole

> Try this:
>
[quoted text clipped - 12 lines]
>
>         }
Steven Nagy - 29 Sep 2006 23:49 GMT
Sorry, I made a mistake in the code I wrote!
I redeclared a variable with the same name when I ment to use the same
form level variable.
Here's the new code (spot the difference!) :

> > frmContentDisplay objChildContentDisplay;
> >
[quoted text clipped - 10 lines]
> >
> >         }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.