如何访问将在运行时创建的按钮 [英] how to access the button which is going to be created at runtime

查看:56
本文介绍了如何访问将在运行时创建的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有将在运行时创建的按钮.所以我应该能够用代码移动那个按钮.为此,我知道我应该使用

i have buuttons which are going to be created at runtime. so i should be able to move that buttons with code. for that i know i should use

Private Sub Runtime Button Name_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles User.MouseDown


同样,我应该使用鼠标移动"和鼠标向上"事件.


这里的问题是我不了解如何命名运行时按钮,因此我应该能够移动该按钮.

请帮助我如何命名在运行时创建的按钮.


Similarly i should use Mouse Move and Mouse Up Events.


Problem here is I am not understanding how to name the runtime button so that i should be able to move that button.

Please help me how to name the button which is created at runtime.

推荐答案

为您的方法指定一个通用名称:例如"CreatedAtRunTimeButton_MouseDown",并设置所有已创建的按钮使用相同的处理程序.然后在处理程序中使用sender参数(投射到Button中)访问按下的按钮.
Give your method a generic name: "CreatedAtRunTimeButton_MouseDown" for example, and set all your created buttons to use the same handler. Then within the handler use the sender parameter (cast into a Button) to access which button was pressed.
Dim b As Button = TryCast(sender, Button)
If b IsNot Nothing Then
    Dim text As String = b.Text
End If


这篇关于如何访问将在运行时创建的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆