将窗口应用程序窗体转换为dll时出错 [英] get an error when convert window application form into dll

查看:55
本文介绍了将窗口应用程序窗体转换为dll时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有6个窗口应用程序表单需要转换为dll(s)因为我需要将这6个应用程序放入另一个大窗口应用程序表单中。我尝试使用此说明转换其中一个( 如何将Windows窗体转换为dll [ ^ ]),但收到这么多错误。



例如:

Handles子句需要在包含类型或其基本类型中定义的WithEvents变量。

无法找到事件'Load'。

'Visible'不是'GillWind1.GillWind1'的成员。

'TextBox1'不是'GillWind1.GillWind1'的成员。

'结束'声明不能是在类库项目中使用。

'ComboBox1'未声明。由于其保护级别可能无法访问。



请帮助。

Hi, I have 6 window applications form need to convert into dll(s) since i need to put that 6 applications into another big window application form. i tried to convert 1 of them using this instruction( How to convert a windows form to dll[^] ), but getting so much errors.

e.g:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
Event 'Load' cannot be found.
'Visible' is not a member of 'GillWind1.GillWind1'.
'TextBox1' is not a member of 'GillWind1.GillWind1'.
'End' statement cannot be used in class library projects.
'ComboBox1' is not declared. It may be inaccessible due to its protection level.

Please help.

推荐答案

做一些非常不同的事情。不要移动任何文件或添加任何内容。执行以下操作:



Do something very different. Don't move any files or add anything. Do the following:

  1. 如果您想保留现有的应用程序项目和解决方案(总是一个好主意),请完整填写将其复制到不改变任何内容的其他位置。确保它编译并正常工作。
  2. 转到项目属性,第一个选项卡,将输出类型从Windows应用程序更改为类库。这已经给你一个DLL了。 (请记住,在.NET中,EXE和DLL之间的区别非常小。)
  3. 您有一个类库程序集。对于此程序集,入口点(静态方法 Main )完全是多余的。删除它,并删除仅为此目的或执行此部分代码所需的所有代码。请勿删除与其功能相关的表单和代码。
  4. 查看访问修饰符的代码。请记住,汇编的目的是在其他程序集和其他程序集中使用,以访问需要 public protected <的方法和成员/ code>访问修饰符。 (我在这里没有提到反射;无论访问修饰符如何,它都可以访问任何内容。让我们通过引用程序集来讨论访问。)不要提供比实际需要更多的访问权限。
  5. 现在你需要使用某些应用程序测试库代码。创建一个全新的Windows窗体应用程序。如果要使用库中的某个表单作为此测试应用程序的主要表单,请根据它删除其主表单和代码。
  6. 将对库的引用添加到测试项目中。最好将它们放在同一个解决方案中并使用项目引用(添加引用窗口中的项目选项卡)。对于新应用程序的主要形式,使用库中的一种形式(如果可能;如果这不是目的,则在某些事件上创建表单,如现有表单上的按钮或菜单项单击)。测试你需要的所有东西,解决问题。
  7. 最后用你的测试项目重构你的库项目,记住它作为库的目的。它可能需要更多适当的名称,结构,添加抽象的准备。这是一个非正式的项目;您将需要使用自己的常识并了解项目目的。
  8. 在同一解决方案中,在您的实际应用程序项目中使用您的库。其中一种方法是重新使用您的测试应用程序以用作工作应用程序原型。
  9. 利润!
  1. If you want to preserve your existing application project(s) and solution (always a good idea), make a full copy of it to a different location not changing anything. Make sure it compiles and works.
  2. Go to project Properties, first tab, change "Output Type" from "Windows Application" to "Class Library". This already will give you a DLL. (Remember, in .NET, the difference between "EXE" and "DLL" is very minor.)
  3. You got a class library assembly. For this assembly, entry point (static method Main) is totally redundant. Remove it, and remove all code which is needed only for the purpose or executing this part of code. Don't remove your form(s) and code related to their functionality.
  4. Review your code for access modifiers. Remember that the purpose of your assembly is to be used in other assemblies, and other assemblies, to access the methods and members with need public and protected access modifiers. (I don't mention reflection here; it would access anything regardless of access modifiers. Let's talk about the access through referencing assemblies.) Don't give more access than it is really required.
  5. Now you need to test your library code with some application. Create a brand new Windows Forms application. If you want to use some form from your library as the main form of this test application, remove its main form and the code depending on it.
  6. Add the reference to the library to your test project. It's the best to have them in the same solution and use reference by project (the tab "Projects" in the "Add Reference" window). For the main form of new application, use one of the forms of your library (if possible; if this is not the purpose, create forms on some events, like button or menu item clicks on existing form). Test all you need, fix the problems.
  7. Finally refactor your library project with your test project, keeping in mind its purpose as the library. It may need more adequate names, structure, preparations for adding abstraction. This is a very informal item; you will need to use your own common sense and understanding the the project purpose.
  8. Use your library in your real application project(s), in the same solution. One of the ways to do it is to re-work your test application to be used as the working application prototype.
  9. PROFIT!





这种方式比你试过的方式更顺畅。它完全消除了你所描述的问题,因为你从不做任何危险的步骤,一次只做一步。



现在,说一下两者之间的区别EXE和DLL。真正的区别只是EXE中的名称和入口点。你可以真正引用EXE,就像它是一个库一样。它完美地运作并具有一些现实生活用途。另一方面,您可以创建一个特殊的主机,它将加载和使用DLL或EXE作为应用程序;这种架构的例子就是一些插件架构。



-SA


你应该不惜一切代价避免将库命名为它包含的任何类型。在这种情况下,您将库命名为GillWind1,而它似乎包含一个名为GillWind1的表单。这会导致尝试解决类型的问题。
You should avoid, at all costs, naming the library the same as any type it contains. In this case, you named the library GillWind1 while it seems to contain a form called GillWind1. This causes problems trying to resolve types.


这篇关于将窗口应用程序窗体转换为dll时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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