如何从类中写入表单中的文本框 [英] How do I write to a textbox in a form from within a class
问题描述
我有一个带有一个按钮的表单,Button1和一个文本框,Textbox1
我有一个类,class1如下。
公共类Class1
Public DeForm As Object
Sub doit()
DeForm.Textbox1.text ="它的工作原理"
结束次级
结束班级
我的按钮代码如下
Private Sub Button1_Click (ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
Dim XX作为新Class1
XX。 DeForm =我
XX.doit()
结束子
这是我想要发生的事情..
当我按下Button1时,Class1被安装为XX。
然后我在对象变量DeForm中将我的表格引用发送给XX。
现在,当执行DoIt时,我希望测试字符串它可以正常工作。将
写在我表格的textbox1中,名为Form1。
运行时我收到此错误信息。
"附加信息:未找到类型''Form1'上的公共成员''Textbox1''。
此行上的
。
DeForm.Textbox1.text ="它有效
有人可以帮忙吗?
谢谢
哈米尔。
I have a form with one button, Button1, and a Textbox, Textbox1
I have a class, class1 as follows.
Public Class Class1
Public DeForm As Object
Sub doit()
DeForm.Textbox1.text = "It works"
End Sub
End Class
My button code is as follows
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim XX As New Class1
XX.DeForm = Me
XX.doit()
End Sub
Here is what I want to happen..
When I press Button1, Class1 is instanciated as XX.
Then i send a reference of my form to XX in object variable DeForm .
Now when DoIt is executed, I would like the test string "it works" to be
written in the textbox1 on me form, that is named Form1.
When it runs I get this error message.
"Additional information: Public member ''Textbox1'' on type ''Form1'' not found."
on this line.
DeForm.Textbox1.text = "It works"
Can someone help?
thanks
Hamil.
推荐答案
嗨哈米尔,
那是因为Textbox1不公开所以Class1不能引用它。试试
这个:
公共类Class1
Public DeTextbox As Object
Sub doit()
DeTextbox.Text =它的工作原理
结束次级
结束班级
私人Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
Dim XX作为新Class1
XX.DeTextbox = Textbox1
XX.doit()
End Sub
祝你好运! Ken。
-
Ken Dopierala Jr.
对于优秀的ASP.Net网站托管尝试:
< a rel =nofollowhref =http://www.webhost4life.com/default.asp?refid=Spinlighttarget =_ blank> http://www.webhost4life.com/default.asp?refid=Spinlight
如果您在我这里注册并需要帮助,请给我发电子邮件。
" hamil" <公顷*** @ discussions.microsoft.com>在消息中写道
新闻:D3 ********************************** @ microsof t.com ...
Hi Hamil,
That is because Textbox1 isn''t Public so Class1 can''t refer to it. Try
this:
Public Class Class1
Public DeTextbox As Object
Sub doit()
DeTextbox.Text = "It works"
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim XX As New Class1
XX.DeTextbox = Textbox1
XX.doit()
End Sub
Good luck! Ken.
--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.
"hamil" <ha***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
我有一个带有一个按钮的表单,Button1和一个Textbox,Textbox1
我有一个类,class1如下。
公共类Class1
Public DeForm As Object
Sub doit()
DeForm.Textbox1.text ="它的工作原理
End Sub
End Class
我的按钮代码如下
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
XX.DeForm =我
XX.doit()
End Sub
这是我想要发生的事情..
当我按下Button1时,Class1被安装为XX。
然后我在对象变量DeForm中将我的表单的引用发送到XX。
现在当DoIt被执行时,我想要测试字符串它的工作原理将
写在我的表格上的textbox1中,名为Form1。
运行时我会收到此错误消息。
其他信息:公开类型''Form1'上的成员''Textbox1''不是
找到。
在这一行。
DeForm.Textbox1.text ="它工作"
有人可以帮忙吗?
感谢
Hamil。
I have a form with one button, Button1, and a Textbox, Textbox1
I have a class, class1 as follows.
Public Class Class1
Public DeForm As Object
Sub doit()
DeForm.Textbox1.text = "It works"
End Sub
End Class
My button code is as follows
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim XX As New Class1
XX.DeForm = Me
XX.doit()
End Sub
Here is what I want to happen..
When I press Button1, Class1 is instanciated as XX.
Then i send a reference of my form to XX in object variable DeForm .
Now when DoIt is executed, I would like the test string "it works" to be
written in the textbox1 on me form, that is named Form1.
When it runs I get this error message.
"Additional information: Public member ''Textbox1'' on type ''Form1'' not found."
on this line.
DeForm.Textbox1.text = "It works"
Can someone help?
thanks
Hamil.
" hamil" <公顷*** @ discussions.microsoft.com>在消息中写道
新闻:D3 ********************************** @ microsof t.com ...
"hamil" <ha***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
这就是我想要发生的事情..
当我按下Button1时,Class1被安装为XX。
然后我在对象变量DeForm中将我的表单的引用发送到XX。
现在当执行DoIt时,我希望测试字符串它工作。将
写在我的表格上的textbox1中,名为Form1。
运行时我会收到此错误消息。
其他信息:公开''Form1''上的成员''Textbox1''没有找到。
就行了。
DeForm.Textbox1.text ="它可以工作
有人可以帮忙吗?
Here is what I want to happen..
When I press Button1, Class1 is instanciated as XX.
Then i send a reference of my form to XX in object variable DeForm .
Now when DoIt is executed, I would like the test string "it works" to be
written in the textbox1 on me form, that is named Form1.
When it runs I get this error message.
"Additional information: Public member ''Textbox1'' on type ''Form1'' not
found."
on this line.
DeForm.Textbox1.text = "It works"
Can someone help?
您可以将Modifiers属性更改为Friend。
You can change the Modifiers property to Friend.
" Jeff Johnson [MVP:VB]"写道:
"Jeff Johnson [MVP:VB]" wrote:
" hamil" <公顷*** @ discussions.microsoft.com>在消息中写道
新闻:D3 ********************************** @ microsof t.com。 ..
"hamil" <ha***@discussions.microsoft.com> wrote in message
news:D3**********************************@microsof t.com...
这就是我想要发生的事情..
当我按下Button1时,Class1被安装为XX。
然后我发送一个在对象变量DeForm中将我的表单引用到XX。
现在当执行DoIt时,我希望测试字符串它工作。将
写在我的表格上的textbox1中,名为Form1。
运行时我会收到此错误消息。
其他信息:公开''Form1''上的成员''Textbox1''没有找到。
就行了。
DeForm.Textbox1.text ="它可以工作
有人可以帮忙吗?
Here is what I want to happen..
When I press Button1, Class1 is instanciated as XX.
Then i send a reference of my form to XX in object variable DeForm .
Now when DoIt is executed, I would like the test string "it works" to be
written in the textbox1 on me form, that is named Form1.
When it runs I get this error message.
"Additional information: Public member ''Textbox1'' on type ''Form1'' not
found."
on this line.
DeForm.Textbox1.text = "It works"
Can someone help?
您可以将Modifiers属性更改为Friend。
You can change the Modifiers property to Friend.
你能解释一下吗?修改者的内容??
Hamil。
Could you explain. Modifiers of what??
Hamil.
这篇关于如何从类中写入表单中的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!