具有一组按钮的集合编辑器,如何公开按钮的Click事件 [英] Collection Editor with a collection of Buttons, how to expose the Buttons' Click event

查看:73
本文介绍了具有一组按钮的集合编辑器,如何公开按钮的Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源自Panel的自定义控件,我们称之为CPanel。 CPanel的公共属性之一是List< Button>,名为ButtonList。当CPanel被删除在表单上时,所有CPanel的公共属性都显示在VS Studio(2013)的通常属性网格中。与往常一样,ButtonList属性也在属性网格中显示省略号(...)。单击省略号可以正确调用我的自定义CollectionEditor,它具有自己的属性网格,允许我添加,向上/向下移动项目以及删除它们。选择列表中的按钮还会显示按钮的所有标准属性,就像编辑表单上的单个按钮一样。



但是,不像单个按钮的常用属性网格放在一个表单上,该表单还有一个事件选项卡,用于为Click事件分配各种方法,自定义CollectionEditor属性网格不显示按钮项的事件选项卡。



如何在CollectionEditor的属性网格中显示事件选项卡,以便我可以像往常一样将事件连接到ButtonList中的项目?



这纯粹是一个设计时问题。我没有问题创建ButtonList项目,让它们持久化,让Cpanel通知列表已被更改等等。我只是无法显示事件选项卡。

解决方案

< blockquote>首先,我祝贺你在创建一个自定义CollectionEditor的深奥业务中尽可能地获得!



而且,我犹豫不鼓励你,但是这个这是我几年前研究过的东西,并放弃了。甚至昂贵的商业PropertyGrid替代品,如来自VisualHint的替代品,也不会以你(和我)想要的方式公开事件标签。



我发现PropertyGrid没有只有挑剔才能合作,但解决这个问题的资源......如何展示事件......不是很清楚。我对实现此功能所花费的时间和精力的估计表明,完成其他更重要的事情并不值得花费机会成本。



我可以通过创建一个UserControl来告诉你如何在三分钟内打破Visual Studio 2013,UserControl是自定义组件的主机(继承自Button,或其他),并将公共属性放入类型列表的自定义组件& Button> ;。这对于这种类型的实验来说是令人沮丧的。



然而,几年前在技术时间是很长时间:它在我看来,最近这个领域的有用信息可能会有一个突破......本月......在StackOverFlow的这篇(长篇)帖子中:[ ^ ]。



我现在没时间真正探索Plutonix的代码在这篇文章中,我很期待这样做,并希望它对你有用。



如果你这样做,我真的很感激见到了CodeProject文章,或将来你的Tip-Trick!


查看文章如何使用CollectionEditor编辑和保留集合 [ ^ ]


I have a custom control deriving from Panel, let's call it CPanel. One of CPanel's public properties is a List<Button>, called ButtonList. When CPanel is dropped on a form, all CPanel's public properties are shown in the "usual" property grid in VS Studio (2013). The ButtonList property shows in the property grid with ellipses (...) also, as usual. Clicking on the ellipses correctly invokes my custom CollectionEditor with its own property grid allowing me to add, move items up/down, and delete them. Selecting a Button within the list also shows all the standard properties of the Button much the same as editing a single button dropped on a form would be shown.

However, unlike the usual property grid for a single button dropped on a form which also has an Events tab for assigning various methods to, say, the Click event, the custom CollectionEditor property grid does not show the Events tab for a button item.

How do I show the events tab within the CollectionEditor's property grid so I can wire up events to the items in the ButtonList as usual?

This is purely a design-time question/issue. I have no problem creating ButtonList items, getting them persisted, getting Cpanel notified that the list has been changed, etc. I just can't get the Events tab displayed.

解决方案

First, I congratulate you for getting as far as you have in the esoteric business of creating a custom CollectionEditor !

And, I hesitate to discourage you, but this is something I looked into a few years ago, and gave up on. Even expensive commercial PropertyGrid substitutes, like the one from VisualHint, will not expose the Event Tab in the way you (and I) would like.

I found the PropertyGrid not only "finicky" to work with, but the resources for solving this problem ... how to show Events ... not very clear. My estimation of the amount of time and energy to get this feature implemented indicated it was not worth the "opportunity cost" of getting other, more important things, done.

I could show you how to "break" Visual Studio 2013 in under three minutes by creating a UserControl that was a host to custom Components (inheriting from Button, or whatever), and putting a public Property in the custom Component of Type List&Button>. That's discouraging for this type of experimentation.

However, "a few years ago" is a very long time in techno-time: it appears to me there might be a recent breakthrough for useful information in this area ... this month ... in this (long) post on StackOverFlow: [^].

I don't have time right now to really explore Plutonix's code on this post, but I look forward to doing so, and hope it is useful to you.

If you do work this out, I'd really appreciate seeing a CodeProject article, or Tip-Trick from you in the future !


Look at article How to Edit and Persist Collections with CollectionEditor[^]


这篇关于具有一组按钮的集合编辑器,如何公开按钮的Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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