本文介绍了参考表格上的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这仍然困扰着我。我知道还有其他方法,但是 由于多种原因我希望能够做到这一点很简单。 我有一个包含许多控件的表单。 我在表单设计工具中创建了这些控件,并赋予它们独特的名称。 我希望能够组合一行代码来实现这一点: OtherForm.Label(UniquePart).Text =" Some文本或其他 我似乎无法在表单上构建对控件的引用。我尝试使用字符串来定义它的每一种方法似乎都反对我!怎么 我能把变量变成一个对象引用吗? 当我尝试创建一个控制变量时,它不会让我连接起来并且 为它分配字符串变量。 任何人都有线索? 谢谢, NinerSevenTango 解决方案 您需要在其他形式上设置属性引用你的控件。 如果你只想返回一个标签盒,那么: 在OtherForm中: public readonly property Label (作为字符串索引)作为LabelBox 获取 对于每个Ctr作为Me.Controls中的控件 如果Ctr.name = index则 返回直播(ctr,labelbox) 结束如果 next 不返回 结束获取 结束财产 希望它有所帮助 Chris Well this is still bugging me. I know there are other ways around this, butfor 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 uniquenames. 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 Itry seems to object to me trying to use strings to define it! How the heckcan I get a variable into an object reference? When I try to create a control variable, it won''t let me concatenate andassign 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 LabelBoxGetFor Each Ctr as control in Me.Controlsif Ctr.name = index thenreturn directcast(ctr, labelbox)end ifnextreturn nothingEnd Getend property Hope it helpsChris 这篇关于参考表格上的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 04:00