ControlDesigner

GetHitTest

https://stackoverflow.com/questions/7762397/how-do-i-click-a-usercontrols-child-in-designer

@Bradley: thanks for pointing me in the right direction

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

See the example here: http://msdn.microsoft.com/en-us/library/sycctd1z(v=VS.90).aspx

For the actual click:

http://msdn.microsoft.com/en-us/library/system.windows.forms.design.controldesigner.gethittest(v=VS.90).aspx

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.

Example

 protected override bool GetHitTest(Point point)
        {
            bool flag = false;
            ASVerticalTab tab = Control as ASVerticalTab;
            if (tab != null)
            {
                Point clientPoint = tab.PointToClient(point);

                foreach (Control control in tab.TabPages)
                {
                    ASVerticalTabPage tabPage = control as ASVerticalTabPage;
                    if (tabPage == null)
                    {
                        continue;
                    }
                    var menuItem = tabPage.MenuItem;
                    var actualRectangle = new Rectangle(menuItem.Location, menuItem.Size);
                    if (actualRectangle.Contains(clientPoint))
                    {
                        flag = true;
                        break;
                    }
                }
            }
            return flag;
        }

关于DesignMode

https://stackoverflow.com/questions/4346361/winform-custom-control-designmode-doesnt-return-true-whereas-in-design-mode

LicenseManager.UsageMode is intended for this.

It is in fact the only reliable way to detect if your control is in design mode or not. It's only valid during the constructor, but it can easily be stored in a field of the class for later reference.

The DesignMode property for nested controls will be false even when the container control is in design mode.

在类的构造函数里面,使用一个字段存一下 LicenseManager.UsageMode

相关资料

http://www.cnblogs.com/blueglass/archive/2012/06/01/2530030.html

Extending Design-Time Support

Custom Designers

原文地址:https://www.cnblogs.com/chucklu/p/7113309.html