zoukankan      html  css  js  c++  java
  • 循环遍历窗口控件

            在做界面的时候,有的时候须要推断控件是否为空,假设窗口就有一个须要推断那无所谓,直接写一个函数调用即可。但是有的时候窗口中须要推断非常多控件,比方说注冊时那么多的信息都须要推断,还有就是组合查询一类的等等一些信息,这时候再用调用函数就显得异常麻烦了,由于每个都须要进行推断,这得反复非常多遍。

    当然有问题就有解决方法。由于推断的控件都是来自一个窗口,所以仅仅须要编写一个函数,循环遍历窗口的每个控件即可。详细例如以下:

    <span style="color:#009900;">    ''' <summary>
        ''' 推断窗口中全部控件是否为空
        ''' </summary>
        ''' <param name="frm">窗口变量</param>
        ''' <returns>为空返回True,不为空返回False</returns>
        ''' <remarks></remarks></span>
        Public Function IsAllEmpty(ByVal frm As Form) As Boolean
    
            Dim control As New Control
            For Each ct1 As Control In frm.Controls
                If ct1.GetType() Is GetType(TextBox) Then
                    If ct1.Text.Length = 0 Then
                        MsgBox("信息不完整,请把信息填写完整")
                        ct1.Focus()
                        Return True
                        Exit Function
                    End If
                ElseIf ct1.GetType Is GetType(ComboBox) Then
                    If ct1.Text.Length = 0 Then
                        MsgBox(ct1.Tag.ToString + "不能为空!")
                        ct1.Focus()
                        Return True
                        Exit Function
                    End If
    
                End If
            Next
            Return False
    
        End Function
    
    
    
    <span style="color:#009900;">    ''' <summary>
        ''' 推断部分控件是否为空
        ''' </summary>
        ''' <param name="arrayCt1">控件集合</param>
        ''' <returns>为空返回True,不为空返回False</returns>
        ''' <remarks></remarks></span>
        Public Function SomeIsEmpty(ByVal arrayCt1() As Control) As Boolean
            Dim control As New Control
            For Each ct1 As Control In arrayCt1
                If ct1.GetType() Is GetType(TextBox) Then
                    If ct1.Text.Length = 0 Then
                        MsgBox(ct1.Tag.ToString + "不能为空!", vbOK, "提示信息")
                        ct1.Focus()
                        Return True
                        Exit Function
                    End If
                ElseIf ct1.GetType() Is GetType(ComboBox) Then
                    If ct1.Text.Length = 0 Then
                        MsgBox(ct1.Tag.ToString + "不能为空!", vbOK, "信息提示")
                        ct1.Focus()
                        Return True
                        Exit Function
                    End If
                End If
            Next
    
            Return False
        End Function

  • 相关阅读:
    C语言第三次博客作业---单层循环结构
    C语言第二次博客作业---分支结构
    C语言第一次博客作业——输入输出格式
    C语言--第0次作业
    Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
    Sources
    kuangbin_SegTree E (HDU 1698)
    (MST) HDOJ 1102 Constructing Roads
    kuangbin_SegTree B (HDU 1754)
    kuangbin_SegTree A (HDU 1166)
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4387562.html
Copyright © 2011-2022 走看看