本文介绍了清除多个文本框时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 i使用下面的代码清除表单中的多个文本框但是我收到错误。请告诉我问题 私有 Sub ClearTextBoxes( ByVal depObject As DependencyObject) 对于 i 作为 整数 = 0 VisualTreeHelper.GetChildrenCount(depObject) - 1 如果 TypeOf depObject TextBox 然后 CType (depObject,TextBox).Text = Nothing 结束 如果 ClearTextBoxes(VisualTreeHelper.GetChild(depObject,i)) 下一页 我得到的错误是: 错误4'System.Windows.DependencyObject'类型的表达式永远不能是'System.Windows.Forms.TextBox'类型。 解决方案 您似乎使用了错误的命名空间 TextBox class。 请尝试 System.Windows.Controls .TextBox 。 Hi alli used the below code to clear multiple textbox in a form but i am getting error.please tell me the problemPrivate Sub ClearTextBoxes(ByVal depObject As DependencyObject) For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(depObject) - 1 If TypeOf depObject Is TextBox Then CType(depObject, TextBox).Text = Nothing End If ClearTextBoxes(VisualTreeHelper.GetChild(depObject, i)) NextError i am getting is:Error4Expression of type 'System.Windows.DependencyObject' can never be of type 'System.Windows.Forms.TextBox'. 解决方案 It seems like you use the wrong namespace for the TextBox class.Try System.Windows.Controls.TextBox instead. 这篇关于清除多个文本框时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 23:12