You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio VB.NET模块遍历窗体控件:TextBox属性访问异常问题

解决方案

1. 明确指定TextBox的完整命名空间

编译器错误地将TextBox识别为System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox而非窗体控件类型,直接指定完整命名空间可消除歧义。修改代码如下:

Public Sub writeMano(FileName As String, Frm As FI) ' There are TextBoxes and CheckBoxes in from FI

    Dim str As String
    For Each c As CheckBox In Frm.GroupBox1.Controls.OfType(Of CheckBox)()
        str = c.Tag ' It retrieves the c.Tag value OK
    Next

    For Each c As System.Windows.Forms.TextBox In Frm.GroupBox3.Controls.OfType(Of System.Windows.Forms.TextBox)()
        str = c.Tag ' 可正常访问Tag属性
    Next

End Sub

2. 移除冲突的命名空间导入

打开项目属性的「引用」选项卡,查看「导入的命名空间」列表,若存在System.Windows.Forms.VisualStyles,取消勾选该选项,避免与窗体控件类型命名冲突。

3. 重置Visual Studio智能感知与缓存

  • 关闭Visual Studio,删除项目目录下的bin和obj文件夹,清理编译缓存。
  • 重启Visual Studio后,执行「编辑 -> IntelliSense -> 刷新本地缓存」,修复智能感知异常。
  • 若问题仍存在,通过「工具 -> 导入和导出设置 -> 重置所有设置」恢复VS默认配置。

4. 确认项目引用完整性

右键项目选择「添加引用」,检查是否已勾选System.Windows.Forms程序集,若缺失则添加该引用,确保窗体控件类型可正常识别。

内容的提问来源于stack exchange,提问作者SnippetCutAndPaste

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 10:52:37