我现在要设计一个页面功能的UserControl,有一个属性:PageDirection,如果为0表示纵向排列,如果为1表示横向排列,纸张大小分别为794×1123和1123×794象素。当更新PageDirection的值时自动调整UserControl的大小。由于我想设计成在设计时大小可以调整,在运行时才固定大小,那么这个应该怎么实现呢?我将下面这一段函数放在UserControl_Paint里面,不过好像不行哦,我对UserControl不是很精通,恳请指点!Private Sub UserControl_Paint()
If UserControl.Ambient.UserMode Then
If PageDirection = Horizontal Then
UserControl.Width = 1123 * 15
UserControl.Height = 794 * 15
Else
UserControl.Width = 794 * 15
UserControl.Height = 1123 * 15
End If
End If InitSize
End Sub
If UserControl.Ambient.UserMode Then
If PageDirection = Horizontal Then
UserControl.Width = 1123 * 15
UserControl.Height = 794 * 15
Else
UserControl.Width = 794 * 15
UserControl.Height = 1123 * 15
End If
End If InitSize
End Sub
If Ambient.UserMode Then Err.Raise 382 'set not supported at runtime
m_PageDirection = New_PageDirection
PropertyChanged "PageDirection"
End Property
Private Sub UserControl_Resize()
if UserControl.Ambient.UserMode then
'' 运行时
if PageDirection = Horizontal then
UserControl.Size 1123 * Screen.TwipsPerPixelX, 794 * Screen.TwipsPerPixelY
else
UserControl.Size 794 * Screen.TwipsPerPixelX, 1123 * Screen.TwipsPerPixelY
end if
end if
End Sub'自动调整
Public Property Get PageDirection() As Long
...
End PropertyPublic Property Let PageDirection(ByVal New_PageDirection As Long)
PageDirection = New_PageDirection
PropertyChanged "PageDirection" Call UserControl_Resize ' 调整大小。也可以向你写的做一个InitSize过程。
End Property