固定 Windows 面板尺寸

发布于 2024-10-03 03:03:49 字数 118 浏览 0 评论 0原文

如何使 Windows 面板固定,以便它显示在应用程序内的固定位置。

我所说的面板是指 System.Windows.Forms.Panel

如果需要更多信息请告诉我,

谢谢

How can i make the Windows Panel Fixed so that it displays at a fixed location within the application.

By Panel i mean System.Windows.Forms.Panel

Let me know if more info is needed

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

卸妝后依然美 2024-10-10 03:03:49

0;0 坐标是表单的左上角,您可以将面板定位到您想要的任何位置:

private int x = 10;
private int y = 20;

this.panel1.Location = new Point(x, y); // "Location" property in the designer

然后您需要检查 锚点属性 指定调整父窗体大小时其行为方式。默认情况下,锚点将为顶部、左侧,这意味着它将始终与顶部边框和左侧边框保持相同的距离。

以编程方式设置锚点:

this.panel1.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Right);

如果您不熟悉 winforms 锚点,我建议使用按钮(或其他控件)创建一个简单的可调整大小的表单,并在更改按钮的锚点设置时调整表单大小。

The 0;0 coordinate being the top left corner of your form you can locate the panel wherever you want :

private int x = 10;
private int y = 20;

this.panel1.Location = new Point(x, y); // "Location" property in the designer

You then need to check the anchor property to specify how it will behave when the parent form is resized. By default the anchor will be Top, Left, meaning it will always stay at the same distance from the top border and from the left border.

To set anchors programmatically :

this.panel1.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Right);

If you are unfamiliar with winforms anchors I recommend creating a simple resizeable form with a button (or other control) and play around resizing the form while changing the button's anchor settings.

捂风挽笑 2024-10-10 03:03:49

如果您想修复 winform 中面板的位置和大小,尽管父窗口处于最小化或最大化模式,则使用

   // set panel at location and size
      panel1.Location = new Point(56,72);
      panel1.Size = new Size(264, 152); // Size(width,Height)

如果您想将面板保留在某个固定位置,则将面板属性设置为跟随

锚点...顶部,左侧选择自动调整大小....错误。

在面板属性中使用这些属性。

If you want to fix the location and size of panel in winform despite of Minimize or Maximizes mode of your parent windows then use

   // set panel at location and size
      panel1.Location = new Point(56,72);
      panel1.Size = new Size(264, 152); // Size(width,Height)

If you want to keep your panel at some fixed location then set panel property as follow

anchor ... top, left selected autosize....false.

use these properties in panel property.

很快妥协 2024-10-10 03:03:49

默认情况下,Panel 控件始终位于固定的顶部、左侧位置,就像所有 Windows 窗体控件一样。

By default the Panel control is always at a fixed top,left location as indeed are all windows forms controls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文