如何在.net2.0 winforms中使搜索用户控件通用 [英] How to make a search usercontrol generic in .net2.0 winforms

查看:93
本文介绍了如何在.net2.0 winforms中使搜索用户控件通用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想使其通用的搜索用户控件。

I have a search usercontrol that I'd like to make generic.

控件本身将根据其上下文包含不同的控件集合。例如,它可能是库存物品,人员,地址,作为搜索的上下文。

The control itself will contain a different collection of controls dependent on its context. For example it could be stock items, people, address as the context of the search..

我如何使其足够通用,以使其可以根据搜索上下文准确知道

How can I make it generic enough that based upon the search context it knows exactly what user controls it needs on the form?

然后任何程序员都可以将用户控件拖到其窗体上,设置其上下文,我们就可以了。

Any programmer can then just drag the user control onto their form, set it's context and we are good to go.

我的第一个想法是为所有单个用户控件创建一个基本控件,并且搜索对话框在构造函数中接受这些控件,因此它知道在运行时显示哪些控件。您可以创建基本控件的继承版本并将其传递。或者也许只是设置搜索上下文(枚举),它就会显示出如何在运行时确定用户控件的内容。

My first thought is to create a base control for all the individual user controls and the search dialog accepts these in the constructor so it knows which ones to show at runtime. You can create inherited versions of the base controls and pass these in. Or maybe just set the search context (enum) and it showhow works out what the user controls are at runtime.

都是.net 2.0 Winform

It's all .net 2.0 Winform

为便于阅读而进行了编辑。 Q太冗长,以前也不详细。

Edited for readibilty. Q was far too lenghty and detailed before.

推荐答案

在我们的项目中,我们通过添加具有 CanSearch Search 属性的ISearchable 接口。它们采用了一个用于指定向前或向后的方向参数,并且Search方法还采用了用于执行搜索的字符串和用于指定匹配类型(短语的开头,短语的结尾,短语中包含的等等)的枚举。

On our project, we did this by adding an ISearchable interface with CanSearch and Search properties. These took a direction argument specifying forwards or backwards, and the Search method also took a string for performing the search and an enumeration specifying the type of matching (start of phrase, end of phrase, included in phrase, etc).

然后,我们在层次结构中的所有控件上实现了此接口。然后,将每个控件委托给子控件(如果合适)。我们的容器应用程序将包含一个文本框并找到下一个/上一个按钮。容器将在层次结构中的第一个视图中查询该接口,然后将其链接到该层次结构中每个控件认为合适的目标控件。

We then implemented this interface on all controls in a hierarchy. Each control then delegated to the child controls as it saw fit. Our container application would contain a textbox and find next/previous buttons. The container would query the first view in the hierarchy for the interface, which would then chain down to the target control as seen fit by each control in the hierarchy.

我们实现了剪贴板操作的另一种方法,我们首先直接检查主动关注的控件,以查看它是否支持我们的 ISupportEdit 接口。如果没有,那么我们将使用层次方法。

We implemented an alternative approach for our clipboard operations whereby we checked the actively focused control directly first to see if it supported our ISupportEdit interface. If it did not, we then used the hierarchy approach.

这篇关于如何在.net2.0 winforms中使搜索用户控件通用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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