首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取RectangleShape of Microsoft.VisualBasic.PowerPacks中存在的所有文本框

获取RectangleShape of Microsoft.VisualBasic.PowerPacks中存在的所有文本框
EN

Stack Overflow用户
提问于 2015-08-08 11:41:53
回答 2查看 122关注 0票数 0

我有大约7 textboxes在一个RectangleShapes中,它附带了Microsoft.VisualBasic.PowerPacks dll,我想检索它并应用一些验证。下面的代码从表单中检索所有的textboxes,而这些都不是预期的。有谁知道如何只检索那些在textboxes中的RectangleShape

代码语言:javascript
复制
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,但是我没有其他的想法去获取它!!

欢迎任何建议或想法。下面是textbox for Add Service的图像,它位于RectangleShape1之外

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-08 12:36:31

由于形状没有控件,所以必须检查每个文本框的位置,它们是否位于矩形内。虽然有点乱七八糟,但会奏效的。

这是我的解决办法:

代码语言:javascript
复制
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")
票数 1
EN

Stack Overflow用户

发布于 2015-08-08 12:43:06

我发现每个textbox都有一个名为textbox的属性,并为此设置了一个值,在检索时我这样做了:

代码语言:javascript
复制
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

希望有人觉得有用

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31892738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档