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

  • 相关阅读:
    手撸机器学习算法
    手撸机器学习算法
    《Python深度学习》 Part 1
    使用Gimp制作Windows应用程序图标
    C# 检查硬盘分区是ssd还是hdd
    微信小程序授权登录以及用户信息相关接口调整导致授权框不弹出
    CNN-LSTM
    MIL基本语法
    Akka Platform Guide 关键点梳理
    阿里云windows服务器激活
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4387562.html
Copyright © 2011-2022 走看看