如何获得对对象形式的引用? [英] How to get reference to form of an object?
问题描述
我不确定这个解释是否清楚,但请尝试帮助我.
I am not sure if this explanation is clear but please try to help me.
我不知道如何获得对包含给定控件(对象)的表单类的引用.
I do not know how I can get a reference to class of a form that contains given control (object).
我有一个表单类(Form_Hole).
I have a form class (Form_Hole).
我在此类中有一个使用单选按钮作为参数的Public子项.
I have a Public sub taking radio button as argument in this class.
在另一个文件中,我有一个模块,其中包含特定的功能和子功能.
In another file I have a module I am keeping specific functions and subs.
我通过将窗体的单选按钮之一传递给该子窗体来调用此模块中的一个子窗体.
I call one of subs in this module from form passing one of form's radio buttons to this sub.
现在,我想从此sub内调用在表单类中声明的sub(声明为public).我可以通过明确指定此表单的类来做到这一点.然后就可以了.
Now from within this sub I would like to call sub declared in the form class (declared as public). I can do that by explicitly specifying this form's class. Then it works.
Public Sub KM_RetractRadioButtonCheckedChange(sender As Object, e As EventArgs)
Dim s As RadioButton
s = CType(sender, RadioButton)
Call Form_Hole.RadioButtonImageUpdate(s)
有没有办法让我可以动态地(不是显式地)引用此表单类.
Is there a way so I could get reference to this form class dynamically (not explicitly).
(想法是将此事件处理功能用于不同的形式).为此,我需要引用适当的表单发送者的给定功能.
(idea is to use this event handling function for different forms). To do that I need to reference given function of appropriate form sender is on.
我尝试过这种方法,但是不起作用
I tried like this, but does not work
Public Sub KM_RetractRadioButtonCheckedChange(sender As Object, e As EventArgs)
Dim f As Form
f= CType(sender, RadioButton).FindForm()
Call f.RadioButtonImageUpdate(CType(sender, RadioButton))
找到正确的表格.当我得到
This finds right form. When I get
MsgBox(f.Name)
显示专有名称Form_Hole
It shows proper name Form_Hole
是否可以获取对发件人参数形式的动态引用?
Is there a way to get dynamic reference to form of sender argument?
克里斯.
推荐答案
不确定我是否理解您的问题.您说FindForm不起作用,但是您说它显示来自Form引用的正确名称.那么实际的问题是什么?
Not sure if I understand your question. You say FindForm does not work, but then you say it displays the correct name from the Form reference. So what is the actual problem?
这篇关于如何获得对对象形式的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!