参考表格上的控件 [英] Reference To Controls On A Form

查看:68
本文介绍了参考表格上的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这仍然困扰着我。我知道还有其他方法,但是

由于多种原因我希望能够做到这一点很简单。


我有一个包含许多控件的表单。


我在表单设计工具中创建了这些控件,并赋予它们独特的
名称。


我希望能够组合一行代码来实现这一点:


OtherForm.Label(UniquePart).Text =" Some文本或其他

我似乎无法在表单上构建对控件的引用。我尝试使用字符串来定义它的每一种方法似乎都反对我!怎么

我能把变量变成一个对象引用吗?


当我尝试创建一个控制变量时,它不会让我连接起来并且

为它分配字符串变量。


任何人都有线索?


谢谢,


NinerSevenTango

解决方案

97T写道:

嗯,这仍然困扰着我。我知道还有其他方法可以解决这个问题,但是由于种种原因,我希望能够做到这一点很简单。

我有一个包含多个控件的表单我已经在表单设计工具中创建了这些控件,并赋予它们独特的名称。

我希望能够组合一行允许这样的代码:

OtherForm.Label(UniquePart).Text ="某些文字或其他

我似乎无法构建对a的引用控制表格。我尝试的每一种方法似乎都反对我试图用字符串来定义它!怎么可以把变量变成对象引用?

当我尝试创建一个控制变量时,它不会让我连接并分配字符串变量吧。

任何人都有线索了吗?

NinerSevenTango



您需要在其他形式上设置属性引用你的控件。

如果你只想返回一个标签盒,那么:


在OtherForm中:

public readonly property Label (作为字符串索引)作为LabelBox

获取

对于每个Ctr作为Me.Controls中的控件

如果Ctr.name = index则

返回直播(ctr,labelbox)

结束如果

next

不返回

结束获取

结束财产


希望它有所帮助

Chris


谢谢,Chris,


我知道用这种语言不可能从字符串中按名称汇总

引用。


我想无论我采用哪种方式,每次我想要引用表单上的对象时,我都必须递归

表单,否则在代码中键入

名称。


我希望有人证明我错了。


我以为通过使用af,我想出了一次返回

参考,但我还有别的东西不能正常工作并删除它之前我已经确定将项目保存到新名称会留下相同的形式/>
代码正在使用中,所以我永久丢失了它。 Grrrrrr。


感谢您不厌其烦地回复,


--NinerSevenTango--


克里斯 < no@spam.com>在留言中写道

新闻:哦************** @ TK2MSFTNGP12.phx.gbl ...


你需要在其他形式上设置属性引用你的控件。如果你只想返回一个标签盒,那么:

在OtherForm中:
公共只读属性标签(索引为字符串)作为LabelBox
获取
每个Ctr作为Me.Controls中的控件如果Ctr.name = index然后
返回直播(ctr,labelbox)
结束如果下一个
返回什么结束获取
结束物业

希望有所帮助
Chris



hi,


好像是父子形态问题。考虑formA(父)和

formB(孩子)。


现在你想在formA中创建一些控件并从
$ b中分配值$ b formB。因此,当你创建formB的对象时,你最好使用formA的formB中的函数创建一个

引用,它将帮助你将

值分配给控件以形成A. />

您可以更好地创建两个函数,一个用于参考设置,另外一个

用于在formA的控件中赋值。


如果你要求,我会给你发一个样品。


问候

kashif ahmed
ka **************** @ gmail.com

Well this is still bugging me. I know there are other ways around this, but
for a number of reasons I would like to be able to do this one simple thing.

I have a form with a number of controls on it.

I have created these controls in the form design tool, and given them unique
names.

I would like to be able to put together a line of code that allows this:

OtherForm.Label(UniquePart).Text = "Some text or other"
I can''t seem to build a reference to a control on a form. Every approach I
try seems to object to me trying to use strings to define it! How the heck
can I get a variable into an object reference?

When I try to create a control variable, it won''t let me concatenate and
assign the string variables to it.

Anyone got a clue?

Thanks,

NinerSevenTango

解决方案

97T wrote:

Well this is still bugging me. I know there are other ways around this, but
for a number of reasons I would like to be able to do this one simple thing.

I have a form with a number of controls on it.

I have created these controls in the form design tool, and given them unique
names.

I would like to be able to put together a line of code that allows this:

OtherForm.Label(UniquePart).Text = "Some text or other"
I can''t seem to build a reference to a control on a form. Every approach I
try seems to object to me trying to use strings to define it! How the heck
can I get a variable into an object reference?

When I try to create a control variable, it won''t let me concatenate and
assign the string variables to it.

Anyone got a clue?

Thanks,

NinerSevenTango


You need to setup a property on "otherform" to reference your controls.
If you just want to return a labelbox then:

In OtherForm:
public readonly property Label(Index as String) as LabelBox
Get
For Each Ctr as control in Me.Controls
if Ctr.name = index then
return directcast(ctr, labelbox)
end if
next
return nothing
End Get
end property

Hope it helps
Chris


Thanks, Chris,

I am getting the idea that it is impossible in this language to assemble a
reference by name from a string.

I guess whichever way I go about this, I am going to have to recurse the
form every time I want to refer to an object on a form, or else type the
name out in the code.

I wish someone would prove me wrong.

I thought I had it figured out once, by using a function to return the
reference, but I had something else not working and erased it before I
figured out that saving projects to new names leaves the same form and its
code in use, so I lost it permanently. Grrrrrr.

Thanks for taking the trouble to reply,

--NinerSevenTango--

"Chris" <no@spam.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...


You need to setup a property on "otherform" to reference your controls. If
you just want to return a labelbox then:

In OtherForm:
public readonly property Label(Index as String) as LabelBox
Get
For Each Ctr as control in Me.Controls
if Ctr.name = index then
return directcast(ctr, labelbox)
end if next
return nothing End Get
end property

Hope it helps
Chris



hi,

It seems to be parent child form problem. Consider formA (parent) and
formB (child).

Now u want to create some control in formA and assign values from
formB. So when u create object of formB then u better create a
reference with functions in formB of formA, it will help u assign
values into the controls to formA.

You may better create two functions one for reference setting and other
for assign values in controls of formA.

I will send a sample for u if u request.

regards
kashif ahmed
ka****************@gmail.com


这篇关于参考表格上的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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