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 / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

How to get the main window object from outside the object?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Funnyman - 23 Feb 2007 18:27 GMT
I'm pretty new to .net Windows Forms, but I've done a lot of searching
and can't find an answer to this question. Here's what I'm trying to
do:

main() {
   Form1 myForm = new Form1();
   Application::Run(myForm);
}

Function1()
{
   // I need to modify elements of myForm either
   //   through a class function or by manipulating the
   //   object itself.
   return;
}

Basically the app has the main window thread (Application::Run) and
then a listener thread for events coming in from other applications,
and those events need to manipulate the data being shown in the main
window.

Right now, I have hacked it up so that I have a static Form1 pointer
in the Form1 class, and whenever an event is received I do the
following:
   Form1::thisForm->Function();
but, like I said, this feels like a hack.

Any suggestions as to the correct way of doing this would be greatly
appreciated. Thanks very much!

--Mike
Oliver Sturm - 24 Feb 2007 17:48 GMT
Hello Funnyman,

>Basically the app has the main window thread (Application::Run) and
>then a listener thread for events coming in from other applications,
>and those events need to manipulate the data being shown in the main
>window.

There's no really good answer to your question, because you're going wrong
here. You shouldn't be manipulating data that is encapsulated in the main
from class from outside that class. A basic OO paradigm. If you need have
that data changed based on an event, then you should catch that event
inside the class. If that is totally impossible (and I have to admit I'm
not entirely sure why it would be), you should introduce a public
interface to the class that holds the data and call those public methods
to have the necessary modifications made.

>     Form1::thisForm->Function();

Use C#, man - that looks just funny in 2007 :-) Interesting, I never
noticed back in 1996... just joking, in a way...

               Oliver Sturm
Signature

http://www.sturmnet.org/blog


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.