创建一个文本框的实例并指定另一个的名称,更改可见性 [英] Create An Instance of A Text Box and Given the Name Of Another, Change The Visibility

查看:72
本文介绍了创建一个文本框的实例并指定另一个的名称,更改可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个哈希表,其中包含程序中所有文本框的名称.然后,我有一个函数,它接受文本框的字符串名称,并在键列表中搜索该名称.找到此名称后,我想使用文本框的实例来分配目标的名称并更改可见性.鉴于没有找到,我想确保此文本框实例的可见性设置为false.谢谢!

I have a hash table which contains the names of all my textboxes in my program.  Then I have a function which takes in a string name of the text box and searches a the list of keys for the name.  Once this name is found I would like to use the instance of the text box to be assigned the name of my target and change the visibility.  Whereas if it isn't found I would like to ensure that the visibility is set to false with this instance of the textbox.  Thank you!

    Private Sub HideBoxes(ByVal strName As String)
        Dim thisTEXT As TextBox

        For Each objKey In Hash.Keys
            If objKey.ToString = strName Then
                'make this text box visible
            Else
                'set the visibility to false
            End If
        Next
    End Sub


推荐答案

此修改可以解决您的问题:

This is a modification that may solve your problem:

Private Sub HideBoxes(ByVal strName As String)
        'Iterate to controls on windows forms
        For Each ctrl In Me.Controls
            'filter to only select textboxes
            If TypeOf (ctrl) Is TextBox Then
                'Check if the name matches any Textbox on the form
                If strName = ctrl.Name Then
                    ctrl.Visible = True
                Else
                    ctrl.Visible = False
                End If
            End If
        Next
    End Sub

您可以根据需要注入哈希.

希望对您有所帮助

You may inject your Hash if needed.

Hope it helps


这篇关于创建一个文本框的实例并指定另一个的名称,更改可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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