如何在C#模块中嵌入ms-access表单? [英] How to embed ms-access forms in C# module?

查看:69
本文介绍了如何在C#模块中嵌入ms-access表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经开发了一个相当沉重的ms-access应用程序,其中包含300多种表单(是的!).当代码实例化这些表单时(不只是打开"它们),我们可以在屏幕上显示同一表单的多个实例.

We have developped quite an heavy ms-access app, with some 300 forms (yes!). As the code instantiates these forms (and do not just 'open' them), we can have multiple instances of the same form displayed on the screen.

要绕过VBA的局限性以及对某些面向对象概念(例如继承,接口,封装等)的不良实现,代码正在管理:

To bypass the limitations of VBA, and its poor implementation of some object oriented concepts such as inheritance, interface, encapsulation, etc, the code is managing:

  • 由窗体的所有活动实例组成的Windows集合.
  • 一个幽灵窗口"对象,其中包含我们代码所需的所有其他属性和方法.

因此,例如,当我想达到我的一个实例的标准属性时,我可以写:

So, as an example, when I want to reach the standard property of one of my instances, I can write:

MyWindows.accessWindow(hWnd).name 

其中hWnd是Windows给定的句柄,并命名为标准form().name属性

Where hWnd is the handle given by Windows, and name the standard form().name property

但是,如果我想达到我的一个实例的特定属性,我可以写:

But if I want to reach a specific property of one of my instances, I can write:

MyWindows.ghostWindow(hWnd).originalRecordset

'originalRecordset'保留原始的ADODB.recordset,它是在首次实例化表单时加载的(意味着在用户进行任何更改之前……都可能很有趣!)

Where 'originalRecordset' holds the original ADODB.recordset which was loaded when the form was first instanciated (meaning before any changes made by the user ... can be interesting!)

这很好用,但是编码它可以成为真正的PITA,特别是当人们知道在C#中做类似的事情有多大的希望时,只要可以将MS-Access表单对象封装到一个更通用的C#对象中.这就是问题所在:可以将MS-Access表单嵌入到自制的C#dll中吗?可行吗?

It's working great, but coding it can be a real PITA, specially when one knows how starighforward it could be to do something similar in C#, as long as one could encapsulate the MS-Access form object into a more generic C# object. So this is the question: could one embed the MS-Access form into a home-made C# dll? Is it feasable?

我不希望得到完整的答案,但是希望获得一些帮助,以使工作步入正轨.有想法的朋友吗?

I do not expect a complete answer, but I am expecting some help to get on the right track. Any idea pals?

推荐答案

这应该可以通过Office Automation来实现.

This should be doable through Office Automation.

简而言之,您可以使用c#启动访问应用程序,然后为您的表单获取正确的对象模型,就像在vba中可用它们的方式一样.

In short, you use c# to launch your access application, and then get the proper object model for your forms, the same way you have them available in vba.

如果您想使用更多的c#(好),而更少的vba(meh)来逐步改善/重构您的访问应用程序,这可能是第一步.

It's probably the first step if you want to use more of c# (good), and less of vba (meh) to gradually improve/refactor your access app.

MS KB文章如何通过使用Visual C#自动化Microsoft Access"中的更多详细信息

这篇关于如何在C#模块中嵌入ms-access表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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