vb 移动窗口

来源:百度知道 编辑:UC知道 时间:2024/06/19 05:31:25
我想把form5移动到form3中picture1的位置,下面是我的代码(在form3的code中):

Dim r2 As RECT

GetWindowRect Picture1.hwnd, r2

Form5.ScaleMode = vbPixels '设置坐标单位为像素

Form5.Move r2.Left, r2.Top

Form5.Show

为什么移动的坐标仍然是默认的缇而不是屏幕像素呢?
请指教!
要实现窗口的正确移动,应该怎么做?

将form5的左上角的位置挪到form3中picture1左上角的位置

'form3中
Private Type rect
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As rect) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Private Sub Command1_Click()
Dim wrect As rect
Dim picrect As rect

GetWindowRect Picture1.hwnd, picrect
GetWindowRect Form5.hwnd, wrect
MoveWindow Form5.hwnd, picrect.Left, picrect.Top, wrect.Right - wrect.Left, wrect.Bottom - wrect.Top, True
Form5.Show
End Sub

可能时我的水平低,但是我还没有听说过VB能够将一个窗体包含在另外一个窗体中,你上面的代码是打开了一个Form5窗体,而不是将Form5窗体包含在Form3窗体中,在一个窗体中包含多项内容,在VB中使用的控件比较多,例如框架(Frame)就是比较常用的。