从dll类重写表单方法 [英] override form method from dll class

查看:86
本文介绍了从dll类重写表单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建处理system.windows.forms.form的dll文件如何覆盖dll类中的任何表单方法,如(WndProc)?



  public   partial   class  MyDll 
{
public MyDll(System.Windows.Forms.Form表格)
{
< span class =code-comment> // 我想从我的dll文件覆盖WinProc表单。
}
}

解决方案

与EXE文件完全相同。没有区别。



在.NET中,EXE或DLL之间的区别是无关紧要的。一切都是集会; EXE或DLL文件是程序集的模块(通常是主模块)。 EXE有一个要作为应用程序执行的入口点( Main )。 EXE可以完全用作类库(引用);一个人可以构建一些alernative托管系统,其中DLL可以扮演可执行的角色。



假设你有应用程序(EXE),它使用了一些库( DLL)。最好的方法是将它们放在同一个解决方案中,并通过添加引用窗口的项目选项卡进行引用(如果这是Visual Studio;其他环境将具有类似的功能)。然后你可以简单地忘记这两个组件之间的边界;写一切,因为它将是整体装配。唯一的要求是 public protected 访问修饰符,以便在不同的程序集中访问类型和成员。 />


但是,如果你想动态地,在运行时,通过改变implementind DLL来改变一些实现,这将使用反射解决更难的问题。如果您有兴趣,我们可以讨论它,但它需要更严格的知识和对基础知识的更深入理解。



-SA

i want to build dll file that deals with system.windows.forms.form how can i override any form method from dll class such as (WndProc)?

public partial class MyDll
{
    public MyDll(System.Windows.Forms.Form form)
    {
        // i want to override WinProc form from my dll file.
    }
}

解决方案

In exact same way as it was in EXE file. There is no difference.

In .NET, the difference between "EXE" or "DLL" is almist insignificant. Everything are assemblies; and "EXE" or "DLL" files are modules (usually, main modules) of the assemblies. EXE has an entry point (Main) to be executed as an application. EXE can be used exactly as class library (referenced); and one can build some alernative hosting system where DLLs could play the roles of executable.

Let's say, you have application ("EXE"), and it uses some library ("DLL"). The best way to do it is having them in the same solution, and reference by the tab "Projects" of the "Add Reference" window (if this is Visual Studio; other environments will have similar features). Then you can simply forget about boundary between these two assemblies; write everything as it would be monolithic assembly. The only requirment is the public or protected access modifiers, to have types and members accessible in a different assembly.

However, if you want dynamically, during runtime, change some implementation by changing implementind DLL, this would much more difficult problem solved using reflection. If you are interested, we can discuss it, but it will require more serious knowledge and deeper understanding of the fundamentals.

—SA


这篇关于从dll类重写表单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆