473,668 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get a reference to main form in a Windows Form 2.0 Application?

Hi

How to get a reference to main form in a Windows Form 2.0 Application?

I'm making a a library and I need a reference to the main form of the
application that is using that library.
TIA

JL
--
Lic. Jorge Luis De Armas García
Chief Software Architect
DATYS Tecnología y Sistemas
email: jl*******@datys .co.cu
jl*******@gmail .com
jl*******@yahoo .com
jl*******@hotma il.com
Aug 25 '06 #1
9 6170
<jl*******@yaho o.comwrote in message
news:OH******** ******@TK2MSFTN GP05.phx.gbl...
How to get a reference to main form in a Windows Form 2.0 Application?

I'm making a a library and I need a reference to the main form of the
application that is using that library.
Have them supply it to you?

-- Alan
Aug 25 '06 #2
Hi
Have them supply it to you?
It could be, but I'm thinking like in Delphi (VCL) that we have property
MainForm in Application object.

Is there something like that?

TIA

JL

--
Lic. Jorge Luis De Armas García
Chief Software Architect
DATYS Tecnología y Sistemas
email: jl*******@datys .co.cu
jl*******@gmail .com
jl*******@yahoo .com
jl*******@hotma il.com
Aug 25 '06 #3
jl*******@yahoo .com wrote:
How to get a reference to main form in a Windows Form 2.0 Application?

I'm making a a library and I need a reference to the main form of the
application that is using that library.
I just spent a few minutes trying to answer this - and it may not be
possible.

* The Application class has nothing like a MainForm property.

* The Application.Run (Form) method doesn't log its parameter anywhere
public; it adds an event handler to the MainForm's Closed event.
There's no way (that I know of) to examine a form's Closed event
handlers to see which has a handler in the Application class; you can
only treat the event as a delegate within the Form class itself.

* The Application.Ope nForms collection seems to be in form creation
order. In most cases, the first form will be the main form - but you
can't count on this. If the Main() procedure creates (and shows) a
form before calling Application.Run , the main form will not be first
in the OpenForms collection.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 25 '06 #4

<jl*******@yaho o.comwrote in message
news:uK******** ******@TK2MSFTN GP05.phx.gbl...
It could be, but I'm thinking like in Delphi (VCL) that we have property
MainForm in Application object.

Is there something like that?
There may be something like that if you're using VB.NET, I'm not sure. If
it were me, I would just have them supply the mainform reference in the
constructor, init routine, or property or whatever. It's very trivial.

-- Alan

Aug 25 '06 #5
Jon Shemitz wrote:
I just spent a few minutes trying to answer this - and it may not be
possible.
I spoke too soon - forgot to Google!

Form MainForm =
(Form)Control.F romHandle(Proce ss.GetCurrentPr ocess().MainWin dowHandle);

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 25 '06 #6
"Jon Shemitz" <jo*@midnightbe ach.comwrote in message
news:44******** *******@midnigh tbeach.com...
Jon Shemitz wrote:
Form MainForm =
(Form)Control.F romHandle(Proce ss.GetCurrentPr ocess().MainWin dowHandle);
But what control would a library (dll) have access to? It is separate from
the exe.

-- Alan
Aug 25 '06 #7
Alan Pretre wrote:
Form MainForm =
(Form)Control.F romHandle(Proce ss.GetCurrentPr ocess().MainWin dowHandle);

But what control would a library (dll) have access to? It is separate from
the exe.
So? It's running in the same process, and using the same
System.Windows. Forms code. In fact, this library

using System;
using System.Diagnost ics;
using System.Windows. Forms;

namespace Get
{
public static class Main
{
public static Form Form
{
get { return
(Form)Control.F romHandle(Proce ss.GetCurrentPr ocess().MainWin dowHandle);
}
}
}
}

works just as well as code in a form event handler ....

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 25 '06 #8
Jon

I had been expecting something like Delphi has in VCL but this is valid too.
Thanks

JL

--
Lic. Jorge Luis De Armas García
Chief Software Architect
DATYS Tecnología y Sistemas
email: jl*******@datys .co.cu
jl*******@gmail .com
jl*******@yahoo .com
jl*******@hotma il.com
"Jon Shemitz" <jo*@midnightbe ach.comescribió en el mensaje
news:44******** *******@midnigh tbeach.com...
Jon Shemitz wrote:
>I just spent a few minutes trying to answer this - and it may not be
possible.

I spoke too soon - forgot to Google!

Form MainForm =
(Form)Control.F romHandle(Proce ss.GetCurrentPr ocess().MainWin dowHandle);

--

.NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.

Aug 25 '06 #9
jl*******@yahoo .com wrote:
I had been expecting something like Delphi has in VCL but this is valid too.
Yeah, the overall architecture of WinForms is a lot like VCL, but
there are a lot of differences in the details.

--

..NET 2.0 for Delphi Programmers www.midnightbeach.com/.net
Delphi skills make .NET easy to learn In print, in stores.
Aug 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
11961
by: Bill Todd | last post by:
Form B needs to call a public method of Form A. How can form B get a reference to the instance of Form A using its name or any other method? Is there a collection of form instances that can be searched? -- Bill
3
3166
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions for the objects on the form, in addition the The objects are created in the fpositional class and affixed to the Input form through the fpositional constructor which takes the form as an argument. The ComboBox and TextBox Array classes hold the...
7
6880
by: Danielb | last post by:
I want my application to run most of the time as just an notify icon visible in the system tray, with some dialogs windows that open if the user selects an option from the context menu on the tray icon. I've had a look at the example on code project that creates an application that runs in the system tray: http://www.codeproject.com/csharp/desktop_mail_checker.asp So I copied how the above article sets up the main form: the form's...
2
1133
by: FredC | last post by:
OS Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1 Microsoft Visual C# .NET 69462-335-0000007-18707 Crystal Reports for Visual Studio .NET AAP50-GS0000S-WCK00C3
1
3594
by: BillZondlo | last post by:
Can someone look at this and tell me why, when I call this from my main app, it displays fine (fades form in and out) but then before my main app displays, I see other dialog boxes flash monentarily on the screen and this delays the main app display? Here is the fade which I compile to a dll and call from my main app: using System; using System.Threading; using System.Timers;
5
2514
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on instead and converted one of the virtual roots that is a seperate
16
2303
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project - even very simple ones. The error says: "An unhandled exception of type 'System.NullReferenceException' occurred in
2
7266
by: Mark D | last post by:
Hi Relative vb.net newbie here... I have a Windows Form application with a few subroutines in a separate module. From one of the subroutines, I want to get the value of a label or text box on the form. As it is, I get a "Reference to a non-shared member requires an object reference." error message. I can't seem to figure out how to tell the subroutine how to find and use the labels or text boxes on the form.
8
6442
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program closes. Dim FORM1 As New Form1 Dim FORM2 As New form2 Sub main() FORM1.Show() FORM2.Show()
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8791
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7398
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5677
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2784
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.