This section describes the implementation of the control glue effect that appears in Windows applications.
has been playing music with Winamp until now using thousands of listening and cool dog, these audio playback software interface in the same vein, and have "control sticky" effect, now let's see how the PDN in this effect is achieved.
In PDN, the effect is implemented by the Snapmanager class and snapobstacle (hereinafter called obstacles) abstract classes, of course, there are auxiliary classes, such as Snapdescription (hereinafter called the definition of glue) class.
Snapmanager as the name implies is the management of adhesion effect, responsible for the positioning of the obstacles, to determine whether the need to adhere to, save the load effect, the formation of sticky objects such as the definition of work.
Snapobstacle is an abstract class that defines the necessary properties of a "sticky" control, including the outline of the obstacle, the distance to stick, the sticky event, and so on.
Then let's see how they work together.
The glue effect is primarily applied to floating windows (toolbars, history, colors, and layers). From the previous article, we've learned about the inheritance relationships of these forms and the interfaces they implement, and here's a quick review:
Pdnbaseform for all forms of the parent class, the implementation of the Isnapmanagerhost interface, all floating windows inherit from the Floatingtoolform, the implementation of the Isnapobstaclehost interface. All "sticky" effects are provided by these two interfaces.
The two interfaces are fairly simple, each of which provides only one property, the Snapmanager and snapobstacle respectively.
Let's take a look at the Snapmanager class, which has explained the main role of the class, no longer verbose, and then look at the code in detail:
Snapmanager Field
1private Dictionary<SnapObstacle, SnapDescription> obstacles =new Dictionary<SnapObstacle, SnapDescription>();
2private const string isSnappedValueName = "IsSnapped";
3private const string leftValueName = "Left";
4private const string topValueName = "Top";
5private const string widthValueName = "Width";
6private const string heightValueName = "Height";
7private const string nullName = "";
8
9private const string snappedToValueName = "SnappedTo";
10private const string horizontalEdgeValueName = "HorizontalEdge";
11private const string verticalEdgeValueName = "VerticalEdge";
12private const string xOffsetValueName = "XOffset";
13private const string yOffsetValueName = "YOffset";