任意のコントロールに対して、ユーザー定義のズームポリシーを作成して適用できます。ここでは、Buttonコントロールについて、ズーム時にボタンのサイズを維持し、本来ズームされるボタンの大きさの中央にボタンを配置する方法について説明します。
はじめに、Buttonコントロールに対するズームポリシーを定義したKeepButtonSizeZoomPolicyクラスを次のコードのように作成します。
Visual Basic コドの書き方
| Visual Basic | 
                         
                            コードのコピー
                         
                     | 
                
|---|---|
                        
' KeepButtonSizeZoomPolicy.vb
Imports C1.Win.C1TouchToolKit
Public Class KeepButtonSizeZoomPolicy
    Inherits ZoomPolicy
    Public Overrides ReadOnly Property TargetType As System.Type
        Get
            Return GetType(Button)
        End Get
    End Property
    Public Overrides Sub ZoomBounds(control As System.Windows.Forms.Control, infos As C1.Win.C1TouchToolKitToolkit.ZoomBoundsInfo)
        Dim button As Button = DirectCast(control, Button)
        If Not button Is Nothing Then
            Dim outer As Rectangle = infos.Zoom(infos.CurrentBounds), inner As New Rectangle(Point.Empty, control.Size)
            Dim offsetX As Integer = outer.X - inner.X, offsetY As Integer = outer.Y - inner.Y
            inner.Offset(offsetX, offsetY)
            button.Bounds = inner
        End If
    End Sub
End Class
                     | 
                |
C# コドの書き方
| C# | 
                         
                            コードのコピー
                         
                     | 
                
|---|---|
                        
// KeepButtonSizeZoomPolicy.cs
using System;
using System.Drawing;
using System.Windows.Forms;
using C1.Win.C1TouchToolKit;
public class KeepButtonSizeZoomPolicy : ZoomPolicy
{
    public override Type TargetType
    {
        get { return typeof(Button); }
    }
    public override void ZoomBounds(Control control, ZoomBoundsInfo infos)
    {
        Button button = control as Button;
        if (button != null)
        {
            Rectangle outer = infos.Zoom(infos.CurrentBounds), inner = new Rectangle(Point.Empty, control.Size);
            int offsetX = outer.X - inner.X, offsetY = outer.Y - inner.Y;
            inner.Offset(offsetX, offsetY);
            button.Bounds = inner;
        }
    }
}
                     | 
                |
次にKeepButtonSizeZoomPolicyクラスを使用するため、以下の手順を実行します。
Visual Basic コドの書き方
| Visual Basic | 
                                 
                                    コードのコピー
                                 
                             | 
                        
|---|---|
                                
Imports C1.Win.C1TouchToolKit
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim myPolicy As New KeepButtonSizeZoomPolicy()
    C1Zoom1.ZoomPolicies.Add(myPolicy)
End Sub
                             | 
                        |
C# コドの書き方
| C# | 
                                 
                                    コードのコピー
                                 
                             | 
                        
|---|---|
                                
using C1.Win.C1TouchToolKit;
private void Form1_Load(object sender, EventArgs e)
{
    KeepButtonSizeZoomPolicy myPolicy = new KeepButtonSizeZoomPolicy();
    C1Zoom1.ZoomPolicies.Add(myPolicy);
}
                             | 
                        |
プロジェクトを実行し、Formをピンチアウトで拡大すると、Button1が元のサイズを維持しており、かつその位置がズーム後のサイズの中央にあることが確認できます。