以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何获得控件的名字  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=35029)

--  作者:ifastudy
--  发布时间:2013/6/22 9:52:00
--  [求助]如何获得控件的名字
我想用SaveConfigValue 实现一个通用的自动保存用户搜索条件的自定义函数。 输入 参数是窗口的名字,这个函数将查找窗口中允许编辑的textbox,comobox等几种控件,然后将它的值放到配置文件吧。代码如下:

If args(0)=""
    Return False
End If

Dim FormName = Args(0)

Dim txb As WinForm.TextBox
Dim ckb As WinForm.CheckBox
Dim rbt As WinForm.RadioButton
Dim cbx As WinForm.ComboBox
Dim chkcbx As WinForm.CheckedComboBox
Dim dtp As WinForm.DateTimePicker

For Each c As WinForm.Control In Forms(FormName).Controls
    If Not c.Enabled Or Not c.ReadOnly
        Continue For
    End If
    
    If Typeof c Is WinForm.TextBox
        txb = c
        SaveConfigValue(FormName & "@" & txb,txb.Value)
    End If
    
错误:txb不能转化为String。经查找,TextBox等控件都没有Name属性。如何知道这个控件的名字呢?
另外,SaveConfigValue的保存的值放到哪里了,用户更新软件版本后这个值还存在吗?

    If Typeof c Is WinForm.CheckBox
        ckb = c
        SaveConfigValue(FormName & "@" & ckb,ckb.Value)
    End If
    
    If Typeof c Is WinForm.RadioButton
        rbt = c
        SaveConfigValue(FormName & "@" & rbt,rbt.Value)
    End If
    
    If Typeof c Is WinForm.ComboBox
        cbx = c
        SaveConfigValue(FormName & "@" & cbx,cbx.Value)
    End If
    
    If Typeof c Is WinForm.CheckedComboBox
        chkcbx = c
        SaveConfigValue(FormName & "@" & chkcbx,chkcbx.Value)
    End If
    
    If Typeof c Is WinForm.DateTimePicker
        dtp = c
        SaveConfigValue(FormName & "@" & dtp ,dtp.Value)
    End If
    
Next

Return True

--  作者:Bin
--  发布时间:2013/6/22 9:59:00
--  
我只看到你 使用txb 并未使用txb.Name  

拖动设计的控件都会有Name值 动态生成的控件也可以手动赋值Name

--  作者:ifastudy
--  发布时间:2013/6/22 10:05:00
--  
哦,行了,是精灵没有提示,我也没有在帮助中找到有这个Name属性。
--  作者:ifastudy
--  发布时间:2013/6/22 10:05:00
--  
SaveConfigValue的保存的值放到哪里了,用户更新软件版本后这个值还存在吗?
--  作者:Bin
--  发布时间:2013/6/22 10:06:00
--  
存在项目文件里,如果用户更新的话是会覆盖掉的.