如何单击设计器中的usercontrol子级?

编程入门 行业动态 更新时间:2024-10-09 01:15:52
本文介绍了如何单击设计器中的usercontrol子级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

创建一个自定义控件时遇到了一些麻烦.

I'm having a bit of trouble with creating one of my custom controls.

我得到的是一个用户控件中的列表框,我需要能够在仍处于设计器中的情况下单击列表项.这会使它的行为像tabcontrol一样.

What I've got is a listbox within a usercontrol, and I need to be able to click on the lists items while still in the designer. This would make it act much like the tabcontrol.

我对用户控件的处理不多,但是我尝试捕获一些覆盖事件但没有成功.

I haven't dealt much with usercontrols but I've tried catching some overide events without success.

protected override void OnClick(EventArgs e) { if (DesignMode) { InvokeOnClick(listBox1, e); } base.OnClick(e); }

我在网上找不到任何东西..关于如何做到这一点的任何想法?

I haven't been able to find anything on the web.. Any ideas on how I can do this?

预先感谢=)

推荐答案

@Bradley:感谢您指出正确的方向

@Bradley: thanks for pointing me in the right direction

您需要编写一个ControlDesigner类,然后在UserControl的[Designer( ... )]属性中使用它.

You will need to write a ControlDesigner class, then use it in a [Designer( ... )] attribute on your UserControl.

在此处查看示例: msdn.microsoft/zh-我们/library/sycctd1z(v=VS.90).aspx

对于实际点击:

msdn.microsoft/zh-cn/library/system.windows.forms.design.controldesigner.gethittest(v = VS.90).aspx

ControlDesigner具有protected bool GetHitTest(Point point)方法-您可以在ControlDesigner中实现该方法,并根据控件在屏幕上的位置,在希望控件处理单击时返回true.

The ControlDesigner has a protected bool GetHitTest(Point point) method - you can implement this in your ControlDesigner and return true when you want your control to handle a click, based on the click's location on the screen.

更多推荐

如何单击设计器中的usercontrol子级?

本文发布于:2023-11-11 08:42:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   器中   usercontrol

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!