使用变量启用按钮 [英] Enabling Buttons Using Variables

查看:84
本文介绍了使用变量启用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有问题的代码:

This is the code in question:

Friend Sub cbxSelRun_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSelRun.SelectedIndexChanged
    Dim tmpBtn As Object = "System.Windows.Forms.Button"
    For i = 1 To 6
        If Dir(a_RunFldr(cbxSelRun.SelectedIndex.ToString + 1) & "\Libraries\" & a_RTLib(i), vbDirectory) <> "" Then
            s_Temp = LSet(a_RTLib(i), 4)
            tmpBtn = "btn" & s_Temp
            tmpBtn.enabled = True
        End If
    Next i
End Sub



{可能很明显},它无法正常工作.我有6个按钮.它们从禁用开始,只有在存在目标文件夹的情况下才应启用.我可以使用冗长的代码来做到这一点,但我更喜欢仅使用For ... Next循环来(1)检查文件夹THEN(2)启用相应的按钮.

这些是常规变量:



It''s not working {probably obvious}. What I have are 6 buttons. They start off disabled and should only be enabled if the target Folder is present. I could do this with lengthy code, but I''d prefer to just use the For...Next loop to (1) Check for the folder THEN (2) Enable the appropriate button.

These are the regular variables:

a_RTLib(1) = "Character"
a_RTLib(2) = "Face"
a_RTLib(3) = "Hair"
a_RTLib(4) = "Hand"
a_RTLib(5) = "Pose"
a_RTLib(6) = "Props"



和按钮名称:



And the button names:

btnChar
btnFace
btnHair
btnHand
btnPose
btnProp



如果需要将按钮名称更改为合适的数字,只要可以在需要时使用变量启用/禁用按钮即可.

任何帮助将不胜感激!

给您和您的和平,
Matthew"Dra" Gon"Stohler



If I need to change the button names to numbers that would be fine, so long as I can get them to enable/disable using variables when I need to.

Any help would be appreciated!

Peace to you and yours,
Matthew "Dra''Gon" Stohler

推荐答案

例如,您可以使用Dictionary:declaration

这样的变量
You may use, for instance a Dictionary: declare
a variable like
Dim dic As New Dictionary(Of String, Button)



然后初始化它:



then initialize it:

dic.Add("Character", btnChar)
dic.Add("Face", btnFace)
' and so on...



然后,您可以使用对应的String来访问每个Button,例如



Then you may access each Button using the corrensponding String, for instance

dic("Character").Enabled = True


这篇关于使用变量启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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