我想实现这样的功能点一个按牛 出现个一个选择窗口,选择图片文件,让后窗体上有个TEXT控件,在控件上显示刚才选择图片的路径!!!

解决方案 »

  1.   

    listbox可以轻松实现像资源管理器一样的功能
    是不是就要这种呢?
      

  2.   

    在窗体上加text1,command1.Private Type BrowseInfo
         hwndOwner As Long
         pIDLRoot As Long
         pszDisplayName As Long
         lpszTitle As Long
         ulFlags As Long
         lpfnCallback As Long
         lParam As Long
         iImage As Long
    End TypeConst BIF_RETURNONLYFSDIRS = 1
    Const MAX_PATH = 260Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    Private Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
         
        'declare variables to be used
         Dim iNull As Integer
         Dim lpIDList As Long
         Dim lResult As Long
         Dim sPath As String
         Dim udtBI As BrowseInfo    'initialise variables
         With udtBI
            .hwndOwner = hwndOwner
            .lpszTitle = lstrcat(sPrompt, "")
            .ulFlags = BIF_RETURNONLYFSDIRS
         End With    'Call the browse for folder API
         lpIDList = SHBrowseForFolder(udtBI)
         
        'get the resulting string path
         If lpIDList Then
            sPath = String$(MAX_PATH, 0)
            lResult = SHGetPathFromIDList(lpIDList, sPath)
            Call CoTaskMemFree(lpIDList)
            iNull = InStr(sPath, vbNullChar)
            If iNull Then sPath = Left$(sPath, iNull - 1)
         End If    'If cancel was pressed, sPath = ""
         BrowseForFolder = sPathEnd FunctionPrivate Sub Command1_Click()
    Dim strResFolder As String
        strResFolder = BrowseForFolder(hWnd, "Please select a folder.")
        Text1.Text = strResFolder
    End Sub
      

  3.   

    在.bas文件中
    Public Type OPENFILENAME
        lStructSize As Long
        hwndOwner As Long
        hInstance As Long
        lpstrFilter As String
        lpstrCustomFilter As String
        nMaxCustFilter As Long
        nFilterIndex As Long
        lpstrFile As String
        nMaxFile As Long
        lpstrFileTitle As String
        nMaxFileTitle As Long
        lpstrInitialDir As String
        lpstrTitle As String
        flags As Long
        nFileOffset As Integer
        nFileExtension As Integer
        lpstrDefExt As String
        lCustData As Long
        lpfnHook As Long
        lpTemplateName As String
    End TypePublic Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long在
    Private Sub Command1_Click()
        Dim ofn As OPENFILENAME
        Dim a As Long    ofn.lStructSize = Len(ofn)
        ofn.hwndOwner = frmMain.hWnd
        ofn.hInstance = App.hInstance
        ofn.lpstrFilter = "图片文件 (*.bmp)" + Chr$(0) + "*.bmp" + Chr$(0)
            ofn.lpstrFile = Space$(254)
            ofn.nMaxFile = 255
            ofn.lpstrFileTitle = Space$(254)
            ofn.nMaxFileTitle = 255
            ofn.lpstrInitialDir = CurDir
            ofn.lpstrTitle = "打开文件"
            ofn.flags = 0        a = GetOpenFileName(ofn)        If (a) Then
            
            Text1.text = Trim$(ofn.lpstrFile)
            
            
            Else
                    'MsgBox "按了取消键"
            End If
            
    End Sub