====UserControl的一个简单问题:如何固定UserControl的大小?

alj 2004-12-09 03:50:14
我现在要设计一个页面功能的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
...全文
206 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
aohan 2004-12-09
  • 打赏
  • 举报
回复
我顶来接分了
lxjlz 2004-12-09
  • 打赏
  • 举报
回复
up
韧恒 2004-12-09
  • 打赏
  • 举报
回复
'' 在此事件中写代码可防止用户在运行时用代码调整控件大小
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 Property

Public Property Let PageDirection(ByVal New_PageDirection As Long)
PageDirection = New_PageDirection
PropertyChanged "PageDirection"

Call UserControl_Resize ' 调整大小。也可以向你写的做一个InitSize过程。
End Property
leolan 2004-12-09
  • 打赏
  • 举报
回复
Public Property Let PageDirection(ByVal New_PageDirection As PageDirectionEnum)
If Ambient.UserMode Then Err.Raise 382 'set not supported at runtime
m_PageDirection = New_PageDirection
PropertyChanged "PageDirection"
End Property

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧