VB6中动态控件的事件处理

前端之家收集整理的这篇文章主要介绍了VB6中动态控件的事件处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在VB6中实现动态控件的事件处理?有任何想法吗?
最简单的方法是声明与控件类型相同的模块级变量,并使用WithEvents关键字.例如 @H_301_5@Option Explicit ' Declare object variable as CommandButton and handle the events.' Private WithEvents cmdObject As CommandButton Private Sub Form_Load() 'Add button control and keep a reference in the WithEvents variable' Set cmdObject = Form1.Controls.Add("VB.CommandButton","cmdOne") cmdObject.Visible = True cmdObject.Caption = "Dynamic CommandButton" End Sub 'Handle the events of the dynamically-added control' Private Sub cmdObject_Click() Print "This is a dynamically added control" End Sub

如果您希望能够通过一个中心例程处理来自许多不同控件(可能是不同类型)的事件,则会有更复杂的变体.

猜你在找的VB相关文章