简体   繁体   English

通用控制-关于基座和锚的简单问题

[英]Universal control - simple question about dock and anchor

I use Visual Studio .NET to develop internal applications. 我使用Visual Studio .NET开发内部应用程序。 I create a Windows control that will display custom status bar information. 我创建一个Windows控件,它将显示自定义状态栏信息。 Different developers will use the control to display the same information in many different applications. 不同的开发人员将使用该控件在许多不同的应用程序中显示相同的信息。 The control must always be displayed at the bottom of the parent form in every application. 在每个应用程序中,控件必须始终显示在父窗体的底部。 It must always be as wide as the form. 它必须始终与表格一样宽。 When the form is resized, the control should be resized and repositioned accordingly. 调整窗体的大小时,应调整控件的大小并相应地重新放置。 How should I do that in the best way and why? 我应该如何以最佳方式做到这一点,为什么? A)Create a property to allow the developers to set the Dock property of the control. A)创建一个属性,以允许开发人员设置控件的Dock属性。 Set the default value of the property to AnchorStyle.Bottom. 将属性的默认值设置为AnchorStyle.Bottom。 B) Create a property to allow the developer to set the Anchor property of the control. B)创建一个属性,以允许开发人员设置控件的Anchor属性。 Set the default value of the property to AnchorStyle.Bottom. 将属性的默认值设置为AnchorStyle.Bottom。

If you want your control to always be at the bottom of it's container then you should use the Dock property. 如果希望控件始终位于其容器的底部,则应使用Dock属性。 Docking a control attaches the control to an edge of it's container or fill the container completely. 停靠控件会将控件附加到容器的边缘或完全填充容器。

Using Anchor defines a constant distance between one or more edges of it's container. 使用Anchor定义容器的一个或多个边缘之间的恒定距离。

Thanks 谢谢

Barry 巴里

Dock is what you are after for this - take a look at the Statusbar control to see. 为此,您需要使用Dock-看一下Statusbar控件即可看到。

Something like this should cover it: 这样的东西应该涵盖了它:

  [DefaultValue(2)]
  public override DockStyles Dock {
    get { return base.Dock; }
    set { base.Dock = value; }
  }

Edit: Seems that 2 is Bottom 编辑:似乎2是底部

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

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