在一个窗体中调用另一个无边框窗体,怎么定位第二个窗体位置??
本帖最后由 michaeliao 于 2012-11-23 16:56:09 编辑 我在一个Form1中调用另外一个无边框Form2,Form2在Form1窗体上显示,但是每次启动Form1的时候,Form2的位置都不同。什么原因?代码如下:
Form1窗体代码如下:
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Dim frmArray(20) As Form
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 4
Set frmArray(i) = New frmBFForm
SetParent frmArray(i).hWnd, Form1.hWnd
frmArray(i).lblNum.Caption = (i + 1)
frmArray(i).Show
Next i
End Sub
Private Sub Form_Resize()
Dim i As Integer
Dim dWidth As Double
dWidth = (Me.Width - 240) / 5
For i = 0 To 4
frmArray(i).Top = 0
frmArray(i).Width = dWidth
frmArray(i).Left = i * frmArray(i).Width
Next i
'
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim frm As Form
For Each frm In Forms
Unload frm
Next
End Sub
Private Sub Form_Resize()
Dim dTemp As Double
Dim dWidth As Double, dHeight As Double
Dim dPicRowHeight As Double
Dim i As Integer
dHeight = Me.Height
dWidth = Me.Width
lblNum.Top = 0
lblNum.Left = 10
lblNum.Width = dWidth - 20
shpCircle.Top = lblNum.Top + lblNum.Height + 10
If dWidth * 0.23 > dHeight * 0.23 Then
dTemp = dHeight * 0.23
Else
dTemp = dWidth * 0.23
End If
shpCircle.Width = dTemp
shpCircle.Height = dTemp
shpCircle.Left = (dWidth - shpCircle.Width) / 2
lblTip.Left = 10
lblTip.Width = dWidth - 20
lblTip.Top = shpCircle.Top + (shpCircle.Height - lblTip.Height) / 2
picRect.Left = 10
picRect.Width = dWidth - 20
picRect.Top = shpCircle.Top + shpCircle.Height + 20
picRect.Height = dHeight - picRect.Top - 30
dPicRowHeight = picRect.Height / 4
For i = 0 To 3
lblItem(i).Left = 10
lblItem(i).Width = picRect.Width - 20
lblItem(i).Top = i * dPicRowHeight + (dPicRowHeight - lblItem(i).Height) / 2
Next i
End Sub