# C1.Win.TouchToolKit.ZoomPolicy

## Content

<div class="doc-site-dotnet-api-container">



  <h1 id="C1_Win_TouchToolKit_ZoomPolicy" data-uid="C1.Win.TouchToolKit.ZoomPolicy" class="text-break">ZoomPolicy Class
</h1>
  <div class="markdown level0 summary"><p>Implements the base class of zoom policies.</p>
</div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
    <div class="level1"><span class="xref">ZoomPolicy</span></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.ControlZoomPolicy.html">ControlZoomPolicy</a></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.DataGridViewZoomPolicy.html">DataGridViewZoomPolicy</a></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.ListViewZoomPolicy.html">ListViewZoomPolicy</a></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.NoZoomFontZoomPolicy.html">NoZoomFontZoomPolicy</a></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.TabControlZoomPolicy.html">TabControlZoomPolicy</a></div>
      <div class="level2"><a class="xref" href="C1.Win.TouchToolKit.ToolStripZoomPolicy.html">ToolStripZoomPolicy</a></div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="C1.Win.TouchToolKit.html">C1.Win.TouchToolKit</a></h6>
  <h6><strong>Assembly</strong>: C1.Win.TouchToolKit.10.dll</h6>
  <h5 id="C1_Win_TouchToolKit_ZoomPolicy_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public abstract class ZoomPolicy</code></pre>
  </div>
  <div class="codewrapper">
    <pre><code class="lang-vbnet hljs">Public MustInherit Class ZoomPolicy</code></pre>
  </div>
  <h5 id="C1_Win_TouchToolKit_ZoomPolicy_remarks"><strong>Remarks</strong></h5>
  <div class="markdown level0 remarks"><p>
<a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.html">ZoomPolicy</a> is an abstract class which
allow user to customize zoom logic for complex control. User should inherit
<a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.html">ZoomPolicy</a> for writing special control.
</p>
</div>
  <h5 id="C1_Win_TouchToolKit_ZoomPolicy_examples"><strong>Examples</strong></h5>
  <p>
  The following code example shows how to use <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.html">ZoomPolicy</a> class to customize zoom policy for your control. 
</p>
<p>
  You can copy the code to a exsit Windows Forms appliction. And set the form in the sample code as start form. 
</p>
<p>
  If you find a licenses error when run this code. Try to drag a <a class="xref" href="C1.Win.TouchToolKit.C1Zoom.html">C1Zoom</a> component to a 
  any Form from tool box can generate the licenses information to this project.
</p>
<pre><code class="lang-csharp">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 &lt; 2; ++i)
		{
			for (int j = 0; j &lt; 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);
			}
		}
	}
}</code></pre>
<pre><code class="lang-csharp">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</code></pre>

  <h3 id="constructors">Constructors
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy__ctor" data-uid="C1.Win.TouchToolKit.ZoomPolicy.#ctor">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.-ctor.html#C1_Win_TouchToolKit_ZoomPolicy__ctor">ZoomPolicy()</a>
        </td>
        <td class="markdown level1 summary"></td>
      </tr>
    </tbody>
  </table>
  <h3 id="properties">Properties
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_Enabled" data-uid="C1.Win.TouchToolKit.ZoomPolicy.Enabled">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.Enabled.html#C1_Win_TouchToolKit_ZoomPolicy_Enabled">Enabled</a>
        </td>
        <td class="markdown level1 summary"><p>Gets or sets a value indicating whether this policy should take effect.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_TargetType" data-uid="C1.Win.TouchToolKit.ZoomPolicy.TargetType">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.TargetType.html#C1_Win_TouchToolKit_ZoomPolicy_TargetType">TargetType</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the type indicates which control type can use this policy.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="methods">Methods
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_CanZoom_System_Windows_Forms_Control_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.CanZoom(System.Windows.Forms.Control)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.CanZoom.html#C1_Win_TouchToolKit_ZoomPolicy_CanZoom_System_Windows_Forms_Control_">CanZoom(Control)</a>
        </td>
        <td class="markdown level1 summary"><p>Determines whether this instance can zoom the specified control.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_CanZoomChildren_System_Windows_Forms_Control_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.CanZoomChildren(System.Windows.Forms.Control)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.CanZoomChildren.html#C1_Win_TouchToolKit_ZoomPolicy_CanZoomChildren_System_Windows_Forms_Control_">CanZoomChildren(Control)</a>
        </td>
        <td class="markdown level1 summary"><p>Determines whether the children controls can be zoomed.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_GetChildren_System_Windows_Forms_Control_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.GetChildren(System.Windows.Forms.Control)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.GetChildren.html#C1_Win_TouchToolKit_ZoomPolicy_GetChildren_System_Windows_Forms_Control_">GetChildren(Control)</a>
        </td>
        <td class="markdown level1 summary"><p>Get the collection of controls contained within the control.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_Initialize_System_Windows_Forms_Control_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.Initialize(System.Windows.Forms.Control)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.Initialize.html#C1_Win_TouchToolKit_ZoomPolicy_Initialize_System_Windows_Forms_Control_">Initialize(Control)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes the control before zoom action start.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_ShouldSerializeValue_System_Object_System_String_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.ShouldSerializeValue(System.Object,System.String)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.ShouldSerializeValue.html#C1_Win_TouchToolKit_ZoomPolicy_ShouldSerializeValue_System_Object_System_String_">ShouldSerializeValue(object, string)</a>
        </td>
        <td class="markdown level1 summary"><p>Determines a value indicating whether the value of the specified object's specified property needs to be persisted.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_Terminate_System_Windows_Forms_Control_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.Terminate(System.Windows.Forms.Control)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.Terminate.html#C1_Win_TouchToolKit_ZoomPolicy_Terminate_System_Windows_Forms_Control_">Terminate(Control)</a>
        </td>
        <td class="markdown level1 summary"><p>Terminate the control after zoom action completely.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_ZoomBounds_System_Windows_Forms_Control_C1_Win_TouchToolKit_ZoomBoundsInfo_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.ZoomBounds(System.Windows.Forms.Control,C1.Win.TouchToolKit.ZoomBoundsInfo)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.ZoomBounds.html#C1_Win_TouchToolKit_ZoomPolicy_ZoomBounds_System_Windows_Forms_Control_C1_Win_TouchToolKit_ZoomBoundsInfo_">ZoomBounds(Control, ZoomBoundsInfo)</a>
        </td>
        <td class="markdown level1 summary"><p>Zoom the control bounds.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Win_TouchToolKit_ZoomPolicy_ZoomFont_System_Windows_Forms_Control_C1_Win_TouchToolKit_ZoomFontInfo_" data-uid="C1.Win.TouchToolKit.ZoomPolicy.ZoomFont(System.Windows.Forms.Control,C1.Win.TouchToolKit.ZoomFontInfo)">
          <a class="xref" href="C1.Win.TouchToolKit.ZoomPolicy.ZoomFont.html#C1_Win_TouchToolKit_ZoomPolicy_ZoomFont_System_Windows_Forms_Control_C1_Win_TouchToolKit_ZoomFontInfo_">ZoomFont(Control, ZoomFontInfo)</a>
        </td>
        <td class="markdown level1 summary"><p>Zoom the control font.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="seealso">See Also</h3>
  <div class="seealso">
      <div><a class="xref" href="C1.Win.TouchToolKit.C1Zoom.ControlFontZooming.html">ControlFontZooming</a></div>
      <div><a class="xref" href="C1.Win.TouchToolKit.C1Zoom.ControlBoundsZooming.html">ControlBoundsZooming</a></div>
  </div>

</div>
