开发者

Making Windows Panel Size Fixed

开发者 https://www.devze.com 2023-01-25 18:53 出处:网络
How can i make the Windows Panel Fixed so that it displays at a fixed location within the application.

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 need开发者_如何学JAVAed

thanks


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消