如何通过点击PropertyGrid找到GridItem?
我正在尝试在 Windows 窗体 PropertyGrid 控件上执行一些自定义 UI 行为。 我希望能够响应单击和双击 GridItems 以更改状态。 例如,翻转二进制或三元变量的状态。
我可以通过查找类型名称“PropertyGridView”的子视图来获取底层视图,并可以挂钩其 Click 事件。 唯一的问题是我该怎么办? 我找不到任何将鼠标坐标映射到网格项的函数。
有一个 SelectedGridItem 但这没有帮助。 您可以在许多地方单击不更新此属性的控件,因此假设 SelectedGridItem 已更新来响应 Click 将得到许多不正确的结果。
除了购买商业地产网格控件或切换到某种网格视图之外,我还能在这里做些什么吗? PropertyGrid 几乎正是我所需要的。 我什至正在考虑使用 Reflector 进行漫游,并使用此控件做一些非常不友好的事情来获取我需要的数据。 :)
更多信息:我确实知道如何使用自定义 UITypeEditor 类,并且已经在其他区域(颜色选择器)中执行此操作。 不幸的是,进行自定义 UI 工作需要额外的单击(浏览或下拉某些 UI)。 例如,我使用 UITypeEditor.PaintValue 嵌入了一个复选框,并且非常希望能够仅单击它来选中/取消选中。
I'm trying to do some custom UI behavior on a Windows Forms PropertyGrid control. I'd like to be able to respond to clicks and double-clicks on the GridItems to change the state. For example, to flip a binary or ternary variable through its states.
I can get at the underlying view by looking up a child of typename "PropertyGridView" and can hook its Click event. Only problem is then what do I do? I can't find any functions that map mouse coordinates onto grid items.
There is a SelectedGridItem but this isn't helpful. There are many places you can click on a control that do not update this property, and so responding to a Click assuming SelectedGridItem is updated will get a lot of incorrect results.
Aside from purchasing a commercial property grid control or switching to a gridview of some kind, is there anything I can do here? The PropertyGrid is almost exactly what I need. I'm even considering wandering through with Reflector and doing some very unfriendly things with this control to get the data out that I need. :)
More info: I do know about using custom UITypeEditor classes, and am already doing this in other areas (color picker). Unfortunately doing custom UI work requires an extra click (to browse or drop-down some UI). For example, I have embedded a checkbox using UITypeEditor.PaintValue and would really like to be able to just click on it to check/uncheck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果需要翻转简单类型的值,可以在属性网格中显示枚举值。 这将自动显示为下拉列表。
如果您需要创建一些更聪明的 UI 编辑器,我建议您查看以下文章,它们解释了如何在属性网格中创建自定义 UI:
http://msdn.microsoft.com/en-us/library/aa302334。 ASPX
http://msdn.microsoft.com/en-us/library/aa302326。 aspx
如果您想处理属性网格中的值更改以在应用程序中执行某些操作或更改属性网格中的值,您可以处理
当属性值改变时
每次更改属性网格后都会引发该错误。
一旦您可以创建自己的 UI 编辑器,就不需要处理鼠标单击和鼠标双击。 UI 编辑器可以是下拉编辑器或模式编辑器。 再次强烈建议您阅读以上文章。 他们都很好。
If you need to flip the values of a simple type you can have an enumeration value displayed in the property grid. This will appear automatically as a drop down list.
If you need to create some more clever UI editor I suggest you'll take a look at the following articles that explain how to create custom UI in the property grid:
http://msdn.microsoft.com/en-us/library/aa302334.aspx
http://msdn.microsoft.com/en-us/library/aa302326.aspx
If you want to handle a value change in the property grid to do something in the application or change the values in the property grid you can handle the
OnPropertyValueChanged
that is raised after each change in the property grid.
Handling the mouse click and the mouse double click are not necessary once you can create your own UI editor. UI editors can be drop down editors or modal editors. Again, I strongly suggest you to read the above articles. They are quite good.