Margin and Padding in Windows Forms Controls

https://msdn.microsoft.com/en-us/library/ms229627.aspx

Margin and Padding

Precise placement of controls on your form is a high priority for many applications.

The System.Windows.Forms namespace gives you many layout features to accomplish this.

Two of the most important are the Margin and Padding properties.

 Margin

The Margin property defines the space around the control that keeps other controls a specified distance from the control's borders.

Padding

The Padding property defines the space in the interior of a control that keeps the control's content (for example, the value of its Text property) a specified distance from the control's borders.

 图示

The following illustration shows the Padding and Margin properties on a control.

 

There is design-time support for this feature in Visual Studio. Also see Walkthrough: Laying Out Windows Forms Controls with Padding, Margins, and the AutoSize Property.

 

 Margin and Dock

Margin是控件和父容器的距离;Padding是控件作为父容器的时候,和内部其他控件的距离。

实际使用的时候,默认的边界距离【snapline出现的时候】。是控件的margin和父容器的padding的距离之和。

 

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.margin(v=vs.110).aspx

Setting the Margin property on a docked control has no effect on the distance of the control from the the edges of its container.

关于Margin属性,在控件使用Dock模式的时候,非DockStyle.None的时候,Margin属性不生效。【可以通过父容器的Padding来控制边界】

Margin属性不生效的方式和DockStyle类型有关,DockStyle.Top和Margin.Top对应,设置DockStyle.Top的时候Margin.Top失效。其他的还保持有效

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(473)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2015-10-18 git源码中的Makefile
2015-10-18 git clone 出错SSL certificate problem, verify that the CA cert is OK.
2015-10-18 linux切换用户
2015-10-18 linux系统中删除文件夹
2015-10-18 linux根目录下的文件夹
2015-10-18 CentOS升级git
2015-10-18 CentOS5.5上安装git
点击右上角即可分享
微信分享提示