调整UserControl中组件的大小 [英] resizing components in a UserControl

查看:84
本文介绍了调整UserControl中组件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问

假设您设计了一个UserControl并在其上添加了几个按钮(简单的示例).

然后,您使用Visual Studio设计器,创建一个新窗体,并添加自制的UserControl(带有两个按钮).

有没有办法在可视化窗体上的UserControl中重新放置控件(无需编程)?

Quick question

Suppose you design a UserControl and add a couple buttons on it (simple example).

You then use the Visual Studio Designer, create a new Form, and add the homemade UserControl (with the two buttons).

Is there a way to reposition controls within the UserControl while it is on the Form visually (without programming)? The two buttons are declared Public.

推荐答案

如果要更改它们在设计器中的位置,则不会.如果要使用设计器,必须在用户控件中进行更改.
If you mean change their position in the designer, no. You must change them in the user control if you want to use the designer.


没有,但是,如果可以通过停靠和锚定实现定位,则它将在调整自定义大小时更新控制自己.

或者,如果您在直接在属性设置器中修改子控件位置的自定义控件上公开属性,那么您应该(尽管我尚未检查)能够在属性中移动子控件窗口
no there isnt, however if you positioning is achievable via docking and anchoring then it will update as you resize the custom control itself.

alternatively, if you expose properties on the custom control that directly modify the child control positions in the property setters then you should (though i haven''t checked) be able to move the child controls through the properties window


实际上我找到了一种技术.

您必须通过从ParentControlDesigner继承来创建设计器类.

您重写Initialize(IComponent component),并通过调用EnableDesignMode添加您希望能够调整大小的组件.

您可以与客户设计师一起装饰用户控件:

[Designer(typeof(MyCustomDesigner))]

而且有效.

很棒.
actually I found a technique.

you have to create a designer class by inheriting from ParentControlDesigner.

You override Initialize(IComponent component), and add the components you want to be able to resize via calling EnableDesignMode.

You decorate your usercontrol with the customer designer:

[Designer(typeof(MyCustomDesigner))]

And it works.

Pretty cool.


这篇关于调整UserControl中组件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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