假设我已经知道一个窗体的A,他里面有个ListBox,2个TEXTbox。
我不知道这些box的名称。如何获得他们的内容阿。/
给出代码并通过的小弟弟送500分!!

解决方案 »

  1.   

    Dim obj As Variant
        
        For Each obj In Me.Controls
            If TypeOf obj Is TextBox Then
                ......'' 用obj.Text取得文本框中的文本
            End If
            If TypeOf obj Is ListBox Then
                ......'' 对ListBox进行相应操作
            End If
        Next
      

  2.   

    Private Sub Form_Load()
    Dim myObj As TextBoxFor Each myObj In Form1.Controls
        myObj.Text = "abc"
    Next
    End Sub
      

  3.   

    dim ctl as control  For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
              .........
             End If
            If TypeOf ctl Is ListBox Then
                ......
            End If
        Next
      

  4.   

    Dim Ctrl As ControlFor Each Ctrl In Controls
      Select Case TypeName(Ctrl)
      Case "TextBox"
        '...
      Case "CommandButton"
        '...  
      Case "Label"
        '...  
      Case Else
      End Select
    Next
      

  5.   

    说来说去就是一个for循环,至于怎么实现,方法应该很多也很容易呀,楼主到底要实现什么东西这么难吗?
      

  6.   

    Option ExplicitPrivate Sub Command1_Click()
        EnumChildWindows Form2.hwnd, AddressOf enumchildwindow, ByVal 0&
    End SubPrivate Sub Form_Load()
        Form2.Show
    End Sub--------------------------------------------------
    Option Explicit
    Public Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
    Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongPublic Const WM_GETTEXT = &HDPublic Function vbGetWindowText(ahWnd As Long) As String
        Dim c                       As Integer
        Dim t                       As String
        If ahWnd = 0 Then Exit Function
        t = String(65536, " ")
        c = SendMessage(ahWnd, 14, 0&, 0&)
        SendMessageByStr ahWnd, 13, c + 1, t
        If InStr(t, Chr$(0)) Then
            t = Left(t, InStr(t, Chr$(0)) - 1)
        End If
        
        If t = "" Then c = GetWindowText(ahWnd, t, 65536)
        vbGetWindowText = t
    End FunctionPublic Function remove0(ByVal src As String) As String
        Dim i As Integer
        Dim s As String
        For i = 1 To Len(src)
            If Mid(src, i, 1) <> Chr(0) Then
                s = s & Mid(src, i, 1)
            Else
                Exit For
            End If
        Next i
        remove0 = s
    End FunctionPublic Function enumchildwindow(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim s As String * 255
        Dim ss As String
        GetClassName hwnd, s, 255
        ss = remove0(s)
        If ss = "ThunderTextBox" Or ss = "Edit" Then
            Debug.Print vbGetWindowText(hwnd)
        End If
        enumchildwindow = 1
    End Function
      

  7.   

    你是说这个窗口不是你写的,你想写一个外挂对不对啊?
    但FINDWINDOW不查找子窗体
      

  8.   

    用FindwindowEx找到他们的句柄,然后用sendmessage给他赋值
    具体方法可以去搜索一下csdn的帖子,这方面的东西很多的
      

  9.   

    dim ctl as control1、在同一程序中获得
      For Each ctl In Me.Controls
            If TypeOf ctl Is TextBox Then
              .........
             End If
            If TypeOf ctl Is ListBox Then
                ......
            End If
        Next
    2、在不同程序中获得
       用消息函数
      

  10.   

    不就是用个for each....next循环嘛,这么简单,我呆瓜都会!