2

有关问题的快速总结,请查看底部的图片。

你好,

我创建了一个Form(名为 BaseForm)作为我所有窗口的基础。这个基本表单包含(为了简单起见)底部的“状态栏”(用户控件)之类的东西。

该状态栏已锁定,因此无法在设计器中移动或调整其大小。它还将它的锚点设置为左、下、右,因此它始终保持在底部并水平调整大小。

现在,当创建另一个Form并更改它继承 MyProject.BaseForm 而不是 System.Windows.Forms.Form 时,状态栏就在那里。

但是现在状态栏的位置和大小存在问题。状态栏的标准位置和大小是错误的。VisualStudio 从 BaseForm 获取位置和大小,而不是应用 Anchor。

我也不能(也不想!)移动/调整状态栏的大小来解决问题。

一种明显且可行的解决方案是将状态栏 Dock 属性设置为底部。但我不能将其用作解决问题的通用解决方案,因为我也有不应停靠的控件。(例如,应该始终位于表单右下角的按钮)

4

2 回答 2

2

You have a simple problem, the control is private so can't be messed with in the derived form. None of its properties are accessible, including Location and Size. Which freezes it solid in the wrong spot on your derived form. The layout engine can't move it either. And why it displays the lock icon.

Go back to the BaseForm, select the user control and change the Modifiers property from Private to Protected. Rebuild. Now you can move it on the derived form where it needs to go.

于 2013-03-29T21:28:00.310 回答
1

I think the best way to approach this is to use a TableLayoutPanel instead of explicit docking. Create a 2 row TableLayoutPanel in the parent form. Make the bottom row AutoSize and put the status bar into that. This way the derived forms are free to add content in the other row which represents the remainder of the control.

于 2013-03-29T19:59:20.307 回答