VBA动态增添事件

fieldset{padding:10px;}

VBA动态添加事件我想做一个九宫格,每个单元格都是由Label动态生成,我想给Label添加鼠标事件,可写完了以后发现只有最后一个单元格有事件,求教各位高手怎么搞定?定义事件的类

PrivateWithEventsm_CellAsMSForms.LabelPrivatem_FormAsmyframePublicSubAddCell(ByValfrmLayoutAsmyframe,ByValcellAsMSForms.Label)Setm_Cell=cellSetm_Form=frmLayoutEndSubPrivateSubm_Cell_MouseDown(ByValButtonAsInteger,ByValShiftAsInteger,ByValXAsSingle,ByValYAsSingle)m_Form.CellMouseDownm_Cell,Button,Shift,X,YEndSub

窗体代码

PrivatemyCellsAsCollectionPublicSubUserForm_Initialize()SetRoomsLayoutEndSubPrivateSubSetRoomsLayout()SetmyCells=NewCollectionDimvLeftAsInteger,vTopAsInteger,tLeftAsInteger,tTopAsIntegerDimiAsInteger,jAsInteger,keyAsStringtLeft=(myframe.Width-50*3)/2tTop=(myframe.Height-50*3)/2Fori=0To2Forj=0To2key=i*100+jvLeft=0vTop=0DimlblFixAsLabelSetlblFix=myframe.Controls.Add(ProgID_Label,"lblFix_"&key,True)If(i<>0)ThenvLeft=50*iEndIfIf(j<>0)ThenvTop=50*jEndIfWithlblFix.Height=50.Width=50.Left=vLeft+tLeft.Top=vTop+tTop.TextAlign=fmTextAlignCenter.BackStyle=fmBackStyleOpaque把自己当傻瓜,不懂就问,你会学的更多

VBA动态增添事件

相关文章:

你感兴趣的文章:

标签云: