Continue with the previous section "Silverlight-based smart form design and development (I)", from which class design will be performed on the system, I use simple ideographic diagrams and key code snippets to describe them and express my design ideas. Next I will start from the design of the Form Design anchor class, and gradually expand and analyze it from the bottom up.
The anchor is a small rectangular box around the control when the control is selected. You can drag a small rectangular box (Anchor) to change the height and width of the control, meanwhile, you can set the visibility of the control anchor to indicate whether the control is selected. As shown in:
I. auchor)
The anchor class mainly contains the anchor location attribute to determine the position of the anchor on the control, such as the top left, top middle, and top right.
1. Class Diagram
2. code snippets
First, let's take a look at the XML code of the auchor Anchor anchor interface. The function of the XML code is to draw a small square through rectangle. The width of the square border is 1px, the border color is black, and fill it with a light blue brush:
<Grid x:Name="LayoutRoot" >
<Rectangle x:Name="rtg" Stroke="Black" StrokeThickness="1" Cursor="Hand" Fill="#FFCBC8DD"></Rectangle>
</Grid>
The implementation code of the auchor Anchor anchor class. The Anchor class mainly sets the anchor's position based on the location attribute and the cursor corresponding to the position:
Code
/// <Summary>
/// Position of the anchor
/// </Summary>
Public Enum auchorlocation {top left, top middle, top right, right middle, left middle, bottom left, bottom middle, bottom right}
/// <Summary>
/// The control class of the anchor.
/// </Summary>
Public partial class auchor: usercontrol
{
Auchorlocation location;
/// <Summary>
/// Obtain or set the position of the anchor.
/// </Summary>
Public auchorlocation location
{
Get {return location ;}
Set
{
Location = value;
If (value = auchorlocation. Upper right | value = auchorlocation. Lower Left) RTG. cursor = cursors. sizenesw;
If (value = auchorlocation. Upper Left | value = auchorlocation. Lower right) RTG. cursor = cursors. sizenwse;
If (value = auchorlocation. Medium | value = auchorlocation. Medium) RTG. cursor = cursors. sizens;
If (value = auchorlocation. middle right | value = auchorlocation. middle left) RTG. cursor = cursors. sizewe;
}
}
}
The above is the design and implementation method of the anchor. Anchor is the basic element of smart form design. First, it is ready for subsequent work, in the next section, we will cover another basic element design container class (designrectangle )......