惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
美团技术团队
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
Jina AI
Jina AI
博客园_首页
M
MIT News - Artificial intelligence
D
DataBreaches.Net
L
LangChain Blog
宝玉的分享
宝玉的分享
F
Fortinet All Blogs
A
About on SuperTechFans
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
腾讯CDC
Vercel News
Vercel News
雷峰网
雷峰网
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】

博客园 - 奇远

网络记事本 用google检索email 读注册表 - 奇远 - 博客园 Crystal Report 部署 读写xml - 奇远 - 博客园 vb.net发邮件 - 奇远 - 博客园 VB.NET程序只能启动一次 - 奇远 - 博客园 dataset遍历表中的数据 - 奇远 - 博客园 vb.net自定义纸张大小 - 奇远 - 博客园 怎样使用水晶报表的推模式? SQL查询语句精华使用简要 vb.net事务处理 各种连接字符串设置 CREATE PROCEDURE 将数字串转换为中文金额字符串 中文转换成拼音函数 运行时动态添加和删除控件 VB类Class设计 VB读写注册表
按钮控件数组
奇远 · 2007-04-05 · via 博客园 - 奇远

Public Class ButtonArray
    Inherits System.Collections.CollectionBase

    Private ReadOnly HostForm As System.Windows.Forms.Form

    '创建类的构造函数。
    ' Visual Basic
    Public Sub New(ByVal host As System.Windows.Forms.Form)
        HostForm = host
        'Me.AddNewButton()
    End Sub

    Public Sub AddNewButton() '?AddHandler aButton.Click, AddressOf ClickHandler


        ' 创建 Button 类的新实例。
        Dim aButton As New System.Windows.Forms.Button
        ' 将按钮添加到集合的内部列表。
        Me.List.Add(aButton)
        ' 将按钮添加到由 HostForm 字段
        ' 引用的窗体的控件集合中。
        HostForm.Controls.Add(aButton)
        ' 设置按钮对象的初始属性。
        aButton.Top = Count * 25
        aButton.Left = 100
        aButton.Tag = Me.Count
        aButton.Text = "按钮 " & Me.Count.ToString


        '将事件与事件处理程序相关联
        AddHandler aButton.Click, AddressOf ClickHandler
    End Sub


    '公开控件数组

    Default Public ReadOnly Property Item(ByVal Index As Integer) As _
   System.Windows.Forms.Button
        Get
            Return CType(Me.List.Item(Index), System.Windows.Forms.Button)
        End Get
    End Property


    Public Sub Remove()
        ' 检查以确保存在要删除的按钮。
        If Me.Count > 0 Then
            ' 从宿主窗体控件集合中删除添加到数组
            ' 的最后一个按钮。请注意在访问数组时
            ' 默认属性的使用。
            HostForm.Controls.Remove(Me(Me.Count - 1))
            Me.List.RemoveAt(Me.Count - 1)
        End If
    End Sub


    '创建公共事件处理程序
    Public Sub ClickHandler(ByVal sender As Object, ByVal e As _
   System.EventArgs)
        MessageBox.Show("您已单击按钮 " & CType(CType(sender, _
           Button).Tag, String))
    End Sub