[]
Implements the base class of zoom policies.
public abstract class ZoomPolicy
ZoomPolicy is an abstract class which allow user to customize zoom logic for complex control. User should inherit ZoomPolicy for writing special control.
The following code example shows how to use ZoomPolicy class to customize zoom policy for your control.
You can copy the code to a exsit Windows Forms appliction. And set the form in the sample code as start form.
If you find a licenses error when run this code. Try to drag a C1Zoom component to a any Form from tool box can generate the licenses information to this project.
public class UserControlZoomPolicyDemo : Form
{
private CheckBox _zoomItemBoundsCheckBox;
private MyControl _myControl;
private MyControlZoomPolicy _myControlZoomPolicy = new MyControlZoomPolicy();
private GcZoom _gcZoom1 = new GcZoom();
public UserControlZoomPolicyDemo()
{
InitializeComponent();
_gcZoom1.Target = this;
// Add MyControl's ZoomPolicy object to GcZoom
_gcZoom1.ZoomPolicies.Add(_myControlZoomPolicy);
_zoomItemBoundsCheckBox.CheckedChanged += _zoomItemBoundsCheckBox_CheckedChanged;
}
void _zoomItemBoundsCheckBox_CheckedChanged(object sender, EventArgs e)
{
_gcZoom1.ZoomFactor = 1f;
_myControlZoomPolicy.ZoomItemBounds = _zoomItemBoundsCheckBox.Checked;
}
private void InitializeComponent()
{
_zoomItemBoundsCheckBox = new CheckBox();
_zoomItemBoundsCheckBox.Text = "ZoomItemBounds";
_zoomItemBoundsCheckBox.Location = new Point(20, 20);
_zoomItemBoundsCheckBox.Size = new Size(120, 20);
_zoomItemBoundsCheckBox.Checked = true;
_myControl = new MyControl();
_myControl.Location = new Point(200, 20);
this.Controls.Add(_zoomItemBoundsCheckBox);
this.Controls.Add(_myControl);
this.Size = new Size(600, 400);
}
}
// Implements a zoom policy for MyControl
internal class MyControlZoomPolicy : ZoomPolicy
{
private bool _zoomItemBounds = true;
public MyControlZoomPolicy()
{
}
public bool ZoomItemBounds
{
get { return _zoomItemBounds; }
set { _zoomItemBounds = value; }
}
// Gets the type indicates which control type can use this policy.
public override Type TargetType
{
get { return typeof(MyControl); }
}
// Zoom the control bounds
public override void ZoomBounds(Control control, ZoomBoundsInfo infos)
{
if (ZoomItemBounds)
{
MyControl myControl = control as MyControl;
myControl.ColumnWidth = infos.Zoom(myControl.ColumnWidth);
myControl.RowHeight = infos.Zoom(myControl.RowHeight);
}
base.ZoomBounds(control, infos);
}
// Zoom the control font
public override void ZoomFont(Control control, ZoomFontInfo infos)
{
base.ZoomFont(control, infos);
}
}
// MyControl component
internal class MyControl : UserControl
{
private int _columnWidth;
private int _rowHeight;
private Brush[,] _brushes = {
{Brushes.AliceBlue, Brushes.Aqua},
{Brushes.Beige, Brushes.BlanchedAlmond},
{Brushes.BurlyWood, Brushes.Chocolate},
{Brushes.Crimson, Brushes.DarkGoldenrod},
{Brushes.DarkMagenta, Brushes.DarkRed},
{Brushes.DarkSlateGray, Brushes.DeepSkyBlue},
{Brushes.Firebrick, Brushes.GhostWhite}
};
public MyControl()
{
InitializeComponent();
this.ColumnWidth = 40;
this.RowHeight = 40;
}
public int ColumnWidth
{
get { return _columnWidth; }
set { _columnWidth = value; }
}
public int RowHeight
{
get { return _rowHeight; }
set { _rowHeight = value; }
}
private void InitializeComponent()
{
this.BackColor = SystemColors.Control;
this.Size = new Size(80, 280);
}
protected override void OnPaint(PaintEventArgs e)
{
Draw(e.Graphics);
base.OnPaint(e);
}
private void Draw(Graphics gObj)
{
gObj.DrawRectangle(SystemPens.ControlDark, 0, 0, this.Width - 1, this.Height - 1);
for (int i = 0; i < 2; ++i)
{
for (int j = 0; j < 7; ++j)
{
Rectangle rect = new Rectangle(i * _columnWidth, j * _rowHeight, _columnWidth, _rowHeight);
rect.Inflate(-6, -6);
gObj.DrawRectangle(SystemPens.ControlDark, rect);
gObj.DrawLine(SystemPens.ControlDarkDark, rect.Left, rect.Top + 1, rect.Right, rect.Top + 1);
gObj.DrawLine(SystemPens.ControlDarkDark, rect.Left + 1, rect.Top, rect.Left + 1, rect.Bottom);
gObj.DrawLine(SystemPens.ControlLightLight, rect.Right + 1, rect.Top, rect.Right + 1, rect.Bottom);
gObj.DrawLine(SystemPens.ControlLightLight, rect.Left, rect.Bottom + 1, rect.Right, rect.Bottom + 1);
rect.Inflate(-1, -1);
rect.Offset(1, 1);
gObj.FillRectangle(_brushes[j, i], rect);
}
}
}
}
Public Class UserControlZoomPolicyDemo
Inherits Form
Private _zoomItemBoundsCheckBox As CheckBox
Private _myControl As MyControl
Private _myControlZoomPolicy As New MyControlZoomPolicy()
Private _gcZoom1 As New GcZoom()
Public Sub New()
InitializeComponent()
_gcZoom1.Target = Me
' Add MyControl's ZoomPolicy object to GcZoom
_gcZoom1.ZoomPolicies.Add(_myControlZoomPolicy)
AddHandler _zoomItemBoundsCheckBox.CheckedChanged, AddressOf _zoomItemBoundsCheckBox_CheckedChanged
End Sub
Private Sub _zoomItemBoundsCheckBox_CheckedChanged(sender As Object, e As EventArgs)
_gcZoom1.ZoomFactor = 1.0F
_myControlZoomPolicy.ZoomItemBounds = _zoomItemBoundsCheckBox.Checked
End Sub
Private Sub InitializeComponent()
_zoomItemBoundsCheckBox = New CheckBox()
_zoomItemBoundsCheckBox.Text = "ZoomItemBounds"
_zoomItemBoundsCheckBox.Location = New Point(20, 20)
_zoomItemBoundsCheckBox.Size = New Size(120, 20)
_zoomItemBoundsCheckBox.Checked = True
_myControl = New MyControl()
_myControl.Location = New Point(200, 20)
Me.Controls.Add(_zoomItemBoundsCheckBox)
Me.Controls.Add(_myControl)
Me.Size = New Size(600, 400)
End Sub
End Class
' Implements a zoom policy for MyControl
Friend Class MyControlZoomPolicy
Inherits ZoomPolicy
Private _zoomItemBounds As Boolean = True
Public Sub New()
End Sub
Public Property ZoomItemBounds() As Boolean
Get
Return _zoomItemBounds
End Get
Set(value As Boolean)
_zoomItemBounds = value
End Set
End Property
' Gets the type indicates which control type can use this policy.
Public Overrides ReadOnly Property TargetType() As Type
Get
Return GetType(MyControl)
End Get
End Property
' Zoom the control bounds
Public Overrides Sub ZoomBounds(control As Control, infos As ZoomBoundsInfo)
If ZoomItemBounds Then
Dim myControl As MyControl = TryCast(control, MyControl)
myControl.ColumnWidth = infos.Zoom(myControl.ColumnWidth)
myControl.RowHeight = infos.Zoom(myControl.RowHeight)
End If
MyBase.ZoomBounds(control, infos)
End Sub
' Zoom the control font
Public Overrides Sub ZoomFont(control As Control, infos As ZoomFontInfo)
MyBase.ZoomFont(control, infos)
End Sub
End Class
' MyControl component
Friend Class MyControl
Inherits UserControl
Private _columnWidth As Integer
Private _rowHeight As Integer
Private _brushes As Brush(,) = {{Brushes.AliceBlue, Brushes.Aqua}, {Brushes.Beige, Brushes.BlanchedAlmond},_
{Brushes.BurlyWood, Brushes.Chocolate}, {Brushes.Crimson, Brushes.DarkGoldenrod}, _
{Brushes.DarkMagenta, Brushes.DarkRed}, {Brushes.DarkSlateGray, Brushes.DeepSkyBlue}, _
{Brushes.Firebrick, Brushes.GhostWhite}}
Public Sub New()
InitializeComponent()
Me.ColumnWidth = 40
Me.RowHeight = 40
End Sub
Public Property ColumnWidth() As Integer
Get
Return _columnWidth
End Get
Set(value As Integer)
_columnWidth = value
End Set
End Property
Public Property RowHeight() As Integer
Get
Return _rowHeight
End Get
Set(value As Integer)
_rowHeight = value
End Set
End Property
Private Sub InitializeComponent()
Me.BackColor = SystemColors.Control
Me.Size = New Size(80, 280)
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
Draw(e.Graphics)
MyBase.OnPaint(e)
End Sub
Private Sub Draw(gObj As Graphics)
gObj.DrawRectangle(SystemPens.ControlDark, 0, 0, Me.Width - 1, Me.Height - 1)
For i As Integer = 0 To 1
For j As Integer = 0 To 6
Dim rect As New Rectangle(i* _columnWidth, j* _rowHeight, _columnWidth, _rowHeight)
rect.Inflate(-6, -6)
gObj.DrawRectangle(SystemPens.ControlDark, rect)
gObj.DrawLine(SystemPens.ControlDarkDark, rect.Left, rect.Top + 1, rect.Right, rect.Top + 1)
gObj.DrawLine(SystemPens.ControlDarkDark, rect.Left + 1, rect.Top, rect.Left + 1, rect.Bottom)
gObj.DrawLine(SystemPens.ControlLightLight, rect.Right + 1, rect.Top, rect.Right + 1, rect.Bottom)
gObj.DrawLine(SystemPens.ControlLightLight, rect.Left, rect.Bottom + 1, rect.Right, rect.Bottom + 1)
rect.Inflate(-1, -1)
rect.Offset(1, 1)
gObj.FillRectangle(_brushes(j, i), rect)
Next
Next
End Sub
End Class
Name | Description |
---|---|
ZoomPolicy() |
Name | Description |
---|---|
Enabled | Gets or sets a value indicating whether this policy should take effect. |
TargetType | Gets the type indicates which control type can use this policy. |
Name | Description |
---|---|
CanZoom(Control) | Determines whether this instance can zoom the specified control. |
CanZoomChildren(Control) | Determines whether the children controls can be zoomed. |
GetChildren(Control) | Get the collection of controls contained within the control. |
Initialize(Control) | Initializes the control before zoom action start. |
ShouldSerializeValue(object, string) | Determines a value indicating whether the value of the specified object's specified property needs to be persisted. |
Terminate(Control) | Terminate the control after zoom action completely. |
ZoomBounds(Control, ZoomBoundsInfo) | Zoom the control bounds. |
ZoomFont(Control, ZoomFontInfo) | Zoom the control font. |