简体   繁体   English

有没有一种方法可以在Designer中为表单中的所有控件一次设置某个属性?

[英]Is there a way to set a certain property for all controls in a form at once in the Designer?

I want to set a certain property ( Anchor ) of all the controls in my main form at once. 我想一次在我的主窗体中设置所有控件的某个属性( Anchor )。 There are around 100 controls and I really don't want to change this property for each single control manually. 大约有100个控件,我真的不想手动更改每个控件的此属性。

I know I can select all available controls at once by typing Ctrl + A . 我知道我可以通过Ctrl + A一次选择所有可用的控件。 The problem then occuring is that the desired property I want to change is not visible in the Properties window. 然后发生的问题是我要更改的所需属性在“属性”窗口中不可见。 And normally it should be visible because all the controls are a type of Control , shouldn't it? 并且通常它应该是可见的,因为所有的控制都是一个类型的Control ,不应该吗?

I also know that I could do it like this: 我也知道我可以这样做:

foreach(Control ctrl in myForm.Controls)
{
   ctrl.Anchor = AnchorStyle.Bottom;
}

But I want to know if thers's a way of doing this using the Designer. 但是我想知道其他人是否是使用Designer进行此操作的方法。 Is there any? 有没有?

通常,如果控件从同一基础派生,则可以一次选择所有控件(使用鼠标单击并拖动或按住Ctrl或在逐个选择它们的同时按住Shift键),然后可以设置它们从控件共享的任何属性。基类。

You can multi-select all controls on the form and see the Anchor property in the Property Grid. 您可以多选表单上的所有控件,然后在“属性网格”中查看“锚点”属性。 When you edit that with multiple controls selected, each selected control will be set to the Anchor value you specify. 当您在选择了多个控件的情况下进行编辑时,每个选定的控件都将设置为您指定的“锚点”值。

But be careful with Ctrl-A--it will select visual controls as well as non-visual components. 但请注意Ctrl-A,它将选择视觉控件以及非视觉组件。 So if you have any components on your form that don't render in the client area of the form (such as the Timer or FolderBrowserDialog form components), the Ctrl-A will continue to show common properties--but because these components don't have an Anchor property, the Anchor property won't appear. 因此,如果表单上有任何未在表单客户区中呈现的组件(例如Timer或FolderBrowserDialog表单组件),则Ctrl-A将继续显示通用属性-但因为这些组件没有没有Anchor属性,则不会显示Anchor属性。 The only properties to appear when multiple controls on a form are selected are those share by all selected controls. 选择表单上的多个控件时,唯一显示的属性是所有选定控件共享的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM