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



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.
.



Relevant Pages

  • Re: Debugging dll newb question
    ... Close all of your VB IDE copies, Open the standard EXE project file. ... but sets the file name for the DLL to itself. ... have to make a UserControl as an OCX to use it in an EXE. ... EXE project, just go to Project-->Add User Control, and start making your ...
    (microsoft.public.vb.general.discussion)
  • Re: ERROR_RESOURCE_TYPE_NOT_FOUND error comes
    ... Made DLL which contains resources like dialog, ... Made a static lib project which contains classes for resources ... This control is populated by lib classes. ... locale ID, and if not found, is defaulted to the app .exe itself. ...
    (microsoft.public.vc.mfc)
  • Re: Multiple DLL exists after installation
    ... Your application won't work if the exe is in some folder and all the ... setups, both with a.dll, so both will install a config file for the logging ... If you have two separate apps surely they need their ... logging Dll so that each logs to an app-specific location. ...
    (microsoft.public.dotnet.framework)
  • Re: Custom Control & Dll Hell
    ... DLL using control is Extension / Regular DLL? ... EXE is MFC exe. ... > of my custom control. ...
    (microsoft.public.vc.mfc.docview)
  • Re: Place Reports In A DLL
    ... No, you can't use a .DLL, that's still not supported (reports have a user ... .EXE if you don't want the users changing them, or you can build them into a ... separate .EXE if you want to distribute them separately and ...
    (microsoft.public.fox.vfp.reports.printing)