从其他表单删除动态添加的按钮 [英] Delete a dynamically added button from another form

查看:90
本文介绍了从其他表单删除动态添加的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下一个按钮时,我会在form1上动态添加按钮.当我按下form2上的按钮时,必须删除form1上的按钮.我该怎么做?

I dynamically add buttons on form1 when I press a button. When I press a button on form2, the buttons on form1 must be deleted. How can I do this?

推荐答案

我可以直接或通过form2的自定义事件来使form1订阅form2的按钮单击事件.然后在form1消息处理程序中删除所需的按钮.

我认为这两种形式都是无模式的.
I would get form1 the subscribe to the button click event of form2, either direct or via a custom event of form2. Then in form1 message handler remove the buttons you want.

I presume both forms are modeless


您可以在Form1中订阅Form2按钮事件,然后对其做出反应.由于表单中的大多数控件默认情况下都是私有的,因此您可能必须将按钮设为公开.

或者,您可以在Form2中发布一个供Form 1订阅的自定义(公共)事件,然后在Form2中触发具有适当操作的事件.
You can subscribe to the Form2 button event in Form1, and just react to it. Since most controls in a form are private by default, you''ll probably have to make the button public.

Alternatively, you can post a custom (public) event in Form2 that Form 1 can subscribe to, and fire that event with the appropriate action has happened in Form2.


这篇关于从其他表单删除动态添加的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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