我想控制CommonDialog1控件在指定的地方出现,怎么实现啊?
是不是要用哪个api函数?知道的朋友告诉下,好吗!
真诚求助!!!!!!!!!!

解决方案 »

  1.   

    CommonDialog的位置其实并不是与加载它的窗体的左上角对齐,而好像是每次都出现在同一个位置。可以用timer控件来处理:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Const HWND_TOPMOST = -1
    Private Const SWP_NOZORDER = &H4Private Sub Command1_Click()
        CommonDialog1.DialogTitle = "mytest"
        Timer1.Enabled = True
        CommonDialog1.ShowOpen
        MsgBox CommonDialog1.FileName
    End SubPrivate Sub Form_Load()
        Timer1.Interval = 10
        Timer1.Enabled = False
    End SubPrivate Sub Timer1_Timer()
        DoEvents
        Dim lhwnd As Long
        lhwnd = FindWindow(vbNullString, CommonDialog1.DialogTitle)
        If lhwnd <> 0 Then
            Timer1.Enabled = False
            SetWindowPos lhwnd, HWND_TOPMOST, 10, 10, 0, 0, SWP_NOZORDER '放置在坐标10,10位置
        End If
    End Sub
    另外,以上代码在编译为exe后才有效。
      

  2.   

    fxy_2002(阿勇)方法不错,简单。happy_sea(开心海) 
    调用API,蛮厉害的。谢谢楼上3位的回复!!