简单介绍:

VS2005提供了一种新的Layout设计方式:基准线(Snaplines)。其中包括 Text baselinemargin / padding snaplines.当拖动控件或者调整控件的大小,都可以看到这些基准线。同时用Ctrl+方向键也可以看到这些基准线。如图1

给自定义Control加上SnapLine(VS2005新特性)
         图1

如果是自定义Control,怎么让它在拖动的时候也出现这样漂亮的基准线呢,本文为你介绍。
首先当然是需要写一个Control了,本例极为简单,旨在介绍SnapLine

给自定义Control加上SnapLine(VS2005新特性)public class CustomControl1 : Control

然后为CustomControl1写一个Designer
给自定义Control加上SnapLine(VS2005新特性)public class CustomControlDesigner : ControlDesigner
 最后把CustomControlDesigner挂在CustomControl
给自定义Control加上SnapLine(VS2005新特性)[Designer( typeof( CustomControlDesigner))]
给自定义Control加上SnapLine(VS2005新特性)
给自定义Control加上SnapLine(VS2005新特性)
public partial class CustomControl1 : Control

 

注意,关键就在SnapLines属性。它表明了可以出现哪些SnapLine。本文只添加了一个BaseLine

Member name

Description

Baseline

与其他Control之间的横方向的主要基准线,当然另一个Control也得有baseline 

Bottom

与其他Control之间的横方向的底部基准线,当然另一个Control也得有Bottom snapline 

Horizontal

与其他Control之间的横方向的中部基准线,当然另一个Control也得有horizontal snapline 

Left

与其他Control之间的纵方向的左基准线,当然另一个Control也得有Left snapline

Right

与其他Control之间的纵方向的右基准线,当然另一个Control也得有Right snapline 

Top

与其他Control之间的横方向的顶部基准线,当然另一个Control也得有Top snapline 

Vertical

与其他Control之间的纵方向的中部基准线,当然另一个Control也得有vertical snapline 


给自定义Control加上SnapLine(VS2005新特性)
图2
 

结束语

SnapLine是一个比较好用的功能,如果是基于VS2005做一个自定义Control的话,这方面考虑细一些用起来会很舒服。细节就是成功的关键。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-07-13
猜你喜欢
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-12-23
相关资源
相似解决方案