Foxtable(狐表)用户栏目专家坐堂 → [求助]如何获得控件的名字


  共有4335人关注过本帖平板打印复制链接

主题:[求助]如何获得控件的名字

帅哥哟,离线,有人找我吗?
ifastudy
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:250 积分:1875 威望:0 精华:1 注册:2013/5/25 18:06:00
[求助]如何获得控件的名字  发帖心情 Post By: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

 回到顶部