Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 获取Microsoft.VisualBasic.PowerPacks矩形中存在的所有文本框_Vb.net_Winforms - Fatal编程技术网

Vb.net 获取Microsoft.VisualBasic.PowerPacks矩形中存在的所有文本框

Vb.net 获取Microsoft.VisualBasic.PowerPacks矩形中存在的所有文本框,vb.net,winforms,Vb.net,Winforms,我有大约7个textbox在RectangleShapes中,这是Microsoft.VisualBasic.PowerPacksdll附带的,我想检索并应用一些验证。我有下面的代码,它从表单中检索所有的文本框,这不是预期的。有人知道如何只检索矩形中的文本框吗 Dim empty = Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0) 'empty will fetch all the textbox

我有大约7个
textbox
RectangleShapes
中,这是
Microsoft.VisualBasic.PowerPacks
dll附带的,我想检索并应用一些验证。我有下面的代码,它从表单中检索所有的
文本框
,这不是预期的。有人知道如何只检索
矩形中的
文本框吗

Dim empty = Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0)
'empty will fetch all the textboxes inside form'
If empty.Any Then
    MessageBox.Show("Some of the fields are empty.!")
    Exit Sub
End If
我尝试了这个
Me.RectangleShape1.Controls
,它是无效的,但我没有任何其他想法来获取它

欢迎提出任何建议或想法。下图显示了一个用于添加服务的
文本框,位于
矩形1


因为形状没有控件,所以您必须检查每个文本框的位置是否在矩形内。虽然有点凌乱,但它会起作用

这是我的解决方案:

Dim txts As New List(Of TextBox)
Dim x1 = RectangleShape1.Left
Dim y1 = RectangleShape1.Top
Dim x2 = RectangleShape1.Left + RectangleShape1.ClientRectangle.Width
Dim y2 = RectangleShape1.Top + RectangleShape1.ClientRectangle.Height
For Each Control In Me.Controls
  If TypeOf Control Is TextBox Then
    Dim txt As TextBox = Control
    Dim tx = txt.Left, ty = txt.Top
    If tx >= x1 And tx <= x2 And ty >= y1 And ty <= y2 Then
       txts.Add(txt)
    End If
  End If
Next
Dim empty = txts.Where(Function(txt) txt.Text.Length = 0)
If empty.Any Then MsgBox("Some field(s) are empty")
Dim txts作为新列表(文本框)
尺寸x1=矩形1.左
尺寸y1=矩形1.顶部
尺寸x2=矩形1.左+矩形1.ClientRectangle.Width
尺寸y2=矩形1.顶部+矩形1.ClientRectangle.Height
对于Me中的每个控件。控件
如果控件类型为TextBox,则
Dim txt作为文本框=控件
Dim tx=txt.Left,ty=txt.Top

如果tx>=x1和tx=y1且ty,因为形状没有控件,所以您必须检查每个文本框的位置是否在矩形内。虽然有点凌乱,但它会起作用

这是我的解决方案:

Dim txts As New List(Of TextBox)
Dim x1 = RectangleShape1.Left
Dim y1 = RectangleShape1.Top
Dim x2 = RectangleShape1.Left + RectangleShape1.ClientRectangle.Width
Dim y2 = RectangleShape1.Top + RectangleShape1.ClientRectangle.Height
For Each Control In Me.Controls
  If TypeOf Control Is TextBox Then
    Dim txt As TextBox = Control
    Dim tx = txt.Left, ty = txt.Top
    If tx >= x1 And tx <= x2 And ty >= y1 And ty <= y2 Then
       txts.Add(txt)
    End If
  End If
Next
Dim empty = txts.Where(Function(txt) txt.Text.Length = 0)
If empty.Any Then MsgBox("Some field(s) are empty")
Dim txts作为新列表(文本框)
尺寸x1=矩形1.左
尺寸y1=矩形1.顶部
尺寸x2=矩形1.左+矩形1.ClientRectangle.Width
尺寸y2=矩形1.顶部+矩形1.ClientRectangle.Height
对于Me中的每个控件。控件
如果控件类型为TextBox,则
Dim txt作为文本框=控件
Dim tx=txt.Left,ty=txt.Top

如果tx>=x1,tx=y1和ty那么我发现每个
文本框都有一个名为
AccessibleDescription
的属性,我已经为此设置了一个值,在检索时,我只做了如下操作:

Dim empty = Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0 
And txt.AccessibleDescription = "JobControls")
If empty.Any Then
     MessageBox.Show("Some of the fields are empty.!")
     Exit Sub
End If

希望有人觉得它有用

我发现每个
textbox
都有一个名为
accessibleddescription
的属性,我为此设置了一个值,在检索时,我只做了如下操作:

Dim empty = Me.Controls.OfType(Of TextBox)().Where(Function(txt) txt.Text.Length = 0 
And txt.AccessibleDescription = "JobControls")
If empty.Any Then
     MessageBox.Show("Some of the fields are empty.!")
     Exit Sub
End If


希望有人觉得它有用

您必须实际测试每个文本框的边界,以确定它是否在矩形的边界内。我会在
RectangeShape1
中放置一个
面板
控件。然后,您可以重新测试
面板。控件
集合。或者只需放置在面板中并设置边框,完全避免任何形状(因为它是vb包,不是.net framework的一部分,如果我没记错的话,并且在部署应用程序时存在一些问题)。无论如何,我总是避免形状。谢谢@nelek的时间和帮助!没问题。干杯:)您必须实际测试每个文本框的边界,以确定它是否在矩形的边界内。我会将
面板
控件放置在
RectangeShape1
中。然后,您可以重新测试
面板。控件
集合。或者只需放置在面板中并设置边框,完全避免任何形状(因为它是vb包,不是.net framework的一部分,如果我没记错的话,并且在部署应用程序时存在一些问题)。无论如何,我总是避免形状。谢谢@nelek的时间和帮助!没问题。干杯:)谢谢你@nelek。。我接受这个作为答案,但我采用了不同的方法,我会把它作为答案发布,这个方法在我测试它的时候起作用。不客气。有很多方法可以通过
.Tag
.Name
或您的答案来实现。谢谢@nelek。。我接受这个作为答案,但我采用了不同的方法,我会把它作为答案发布,这个方法在我测试它的时候起作用。不客气。有许多方法可以通过
.Tag
.Name
或您的答案来实现。当然,您也可以使用
TextBox1.Tag=“JobControls”
。有很多方法:)是的!!同意@nelek.:)当然,您也可以使用
TextBox1.Tag=“JobControls”
。有很多方法:)是的!!同意@nelek.:)