|
|
好不容易学会了动态加载控件.
dim withevents Fram as frame
Set Fram = Me.Controls.Add("VB.Frame", "frame1")
fram.visible=true
以下设置语句略过. .
以上能在form中生成控件frame 并能写事件.
然后 ,我将此移植到类中.
因为需要频繁的使用某窗体的复制品 所以也就写成了一个类 , 然后在类中动态加载控件.
这是问题出来了.
我使用了timer , image ,等多个动态加载的控件 , 好不容易不报错了, 但是程序运行, 还是没有看到控件加载的效果.
以下为代码 ; 代码写在类中 , 并申明类中frm 为 new frm6 (工程中的一个实例窗体)
Private WithEvents CloseImg As Image
Private Sub CloseImg_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If X > 0 And X < CloseImg.Width And Y > 0 And Y < CloseImg.Height Then
CloseImg.Picture = LoadPicture(App.Path & "\界面图片\界面\co3.bmp")
Else
CloseImg.Picture = LoadPicture(App.Path & "\界面图片\界面\co1.bmp")
End If
End Sub
Private Sub SetImg() ' 设置按钮画片.
Set CloseImg = Frm.Controls.Add("VB.Image", "image1")
Set Light = Frm.Controls.Add("vb.timer", "timer1")
With CloseImg
.Visible = True
.ZOrder 0
.Width = 100
.Height = 100
.Stretch = True
.Left = Frm.Width - 100
.TOP = Frm.Height - 100
.TooltipText = "xinghebaye"
.Picture = LoadPicture(App.Path & "\界面图片\界面\co1.bmp")
End With
End Sub
|
|