473,385 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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*******@hotmail.com
Aug 25 '06 #1
9 6133
<jl*******@yahoo.comwrote in message
news:OH**************@TK2MSFTNGP05.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*******@hotmail.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.OpenForms 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*******@yahoo.comwrote in message
news:uK**************@TK2MSFTNGP05.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.FromHandle(Process.GetCurrentProcess ().MainWindowHandle);

--

..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*@midnightbeach.comwrote in message
news:44***************@midnightbeach.com...
Jon Shemitz wrote:
Form MainForm =
(Form)Control.FromHandle(Process.GetCurrentProcess ().MainWindowHandle);
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.FromHandle(Process.GetCurrentProcess ().MainWindowHandle);

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.Diagnostics;
using System.Windows.Forms;

namespace Get
{
public static class Main
{
public static Form Form
{
get { return
(Form)Control.FromHandle(Process.GetCurrentProcess ().MainWindowHandle);
}
}
}
}

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*******@hotmail.com
"Jon Shemitz" <jo*@midnightbeach.comescribió en el mensaje
news:44***************@midnightbeach.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.FromHandle(Process.GetCurrentProcess ().MainWindowHandle);

--

.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
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...
3
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...
7
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...
2
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...
1
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...
5
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...
16
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 -...
2
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...
8
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.