如何从不带参数的函数中获取对调用表单的引用 [英] How to get reference to the Calling Form from function without parameter
问题描述
我有两个项目。一个是GUI,另一个是DLL。
I have two projects. One is GUI, and the second is DLL.
我在Form1的DLL中调用函数
I Call a function In DLL from Form1
DLL函数必须连接表单(例如,更改背景色)
The DLL function has to interface the form (Say, Change Back Color)
我想将Calling表单作为引用,而不必传递为参数。
I would like to get the Calling form as a reference, without passing as parameter.
此处是表格1的示例
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ChangeBackColor()
End Sub
DLL函数
Public Sub ChangeBackColor()
Dim CallingForm as Form
'''GET PARENT HERE'''
CallingForm.BackColor = Color.Cyan
End Sub
很明显,如果我每次都通过Form,我可以做到这一点,但是要避免这种情况。
预先感谢
Obviously, I can do this if I pass Form every time, But trying to avoid that. Thank in advance
有人指出此问题已在其他地方回答。据我所知,它尚未得到回答(或询问)。这是特定于引用表单,而不是引用方法或其他对象。
Someone Noted this question has been answered elsewhere. It has not been answered (or asked) as far as I could see. This is specific to Referencing a Form, not a method or other Object.
我已经通过引用Form.ActiveForm获得了引用调用表单的解决方案,现在我正在回答
I have gotten the solution to reference the calling form, by referencing Form.ActiveForm And am now answering my own question below.
推荐答案
我最终使用
I ended up calling the active form by using
Form.ActiveForm
以下功能现在(以及其他功能)可用
The following Function works now (along with others)
Public Sub ChangeBackColor()
Dim CallingForm as Form
'''GET PARENT HERE'''
CallingForm = Form.ActiveForm
CallingForm.BackColor = Color.Cyan
End Sub
感谢所有尝试帮助的人
这篇关于如何从不带参数的函数中获取对调用表单的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!