如何单击设计器中的usercontrol子级? [英] How do I click a usercontrols child in designer?

查看:97
本文介绍了如何单击设计器中的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.

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

对于实际点击:

http://msdn.microsoft.com/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子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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