[]
Represents the component which can be attached to any existing form, and made all forms in current application can be zoom by two finger touch.
[ToolboxBitmap(typeof(C1ApplicationZoom), "ApplicationZoom.png")]
public class C1ApplicationZoom : Component, IComponent, IDisposable
The C1ApplicationZoom will try to find all forms in current application, and then attach a C1Zoom component to the found forms. Before attach C1ApplicationZoom will initialize the C1Zoom's setting by this own settings. And then raise C1ZoomAttaching and C1ZoomAttached event. User can change the initial in this events' event handler and user can cancel attach in C1ZoomAttaching event by set C1ZoomAttachingEventArgs's Cancel property to true.
If the form has attached a C1Zoom, the C1ApplicationZoom do not attach it again.
The C1ApplicationZoom can't make the tooltip, contextMenu, common dialog's has gesture zoom ability.
The following code example shows how to use C1ApplicationZoom component.
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 C1ApplicationZoom 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 GcApplicationZoomDemo
Inherits Form
Private _showFormButton As Button
Private _showForm2Button As Button
Private _gcApplicationZoom As GcApplicationZoom
Public Sub New()
InitializeComponent()
AddHandler _showFormButton.Click, AddressOf _showFormButton_Click
AddHandler _showForm2Button.Click, AddressOf _showForm2Button_Click
AddHandler _gcApplicationZoom.GcZoomAttaching, AddressOf _gcApplicationZoom_GcZoomAttaching
AddHandler _gcApplicationZoom.GcZoomAttached, AddressOf _gcApplicationZoom_GcZoomAttached
AddHandler _gcApplicationZoom.GcZoomDetached, AddressOf _gcApplicationZoom_GcZoomDetached
End Sub
Private Sub _gcApplicationZoom_GcZoomAttaching(sender As Object, e As GcZoomAttachingEventArgs)
' May be some forms should not be zoom.
If TypeOf e.Form Is NormalForm Then
e.Cancel = True
Else
e.GcZoom.AutoShowControl = True
End If
End Sub
Private Sub _gcApplicationZoom_GcZoomAttached(sender As Object, e As GcZoomAttachedEventArgs)
' If you want specific GcZoom's setting different from GcApplicationZoom, You can change it in
' GcZoomAttaching or GcZoomAttached event.
e.GcZoom.MaxZoomFactor = 4.0F
If TypeOf e.Form Is ZoomForm Then
AddHandler e.GcZoom.ZoomFactorChanged, AddressOf TryCast(e.Form, ZoomForm).ZoomFactorChangeProc
End If
End Sub
Private Sub _gcApplicationZoom_GcZoomDetached(sender As Object, e As GcZoomDetachedEventArgs)
If TypeOf e.Form Is ZoomForm Then
RemoveHandler e.GcZoom.ZoomFactorChanged, AddressOf TryCast(e.Form, ZoomForm).ZoomFactorChangeProc
End If
End Sub
Private Sub _showFormButton_Click(sender As Object, e As EventArgs)
Dim form As Form = New ZoomForm()
form.Show()
End Sub
Private Sub _showForm2Button_Click(sender As Object, e As EventArgs)
Dim form As Form = New NormalForm()
form.Show()
End Sub
Private Sub InitializeComponent()
_gcApplicationZoom = New GcApplicationZoom()
_showFormButton = New Button()
_showFormButton.Text = "Click to open ZoomForm"
_showFormButton.Location = New Point(20, 20)
_showFormButton.Size = New Size(200, 40)
_showForm2Button = New Button()
_showForm2Button.Text = "Click to open NormalForm"
_showForm2Button.Location = New Point(20, 80)
_showForm2Button.Size = New Size(200, 40)
Me.Controls.Add(_showFormButton)
Me.Controls.Add(_showForm2Button)
End Sub
End Class
Friend Class ZoomForm
Inherits Form
Private _showFormButton As Button
Public Sub New()
InitializeComponent()
AddHandler _showFormButton.Click, AddressOf _showFormButton_Click
End Sub
Public Sub ZoomFactorChangeProc(sender As Object, e As EventArgs)
Console.WriteLine(GcApplicationZoom.GetGcZoom(Me).ZoomFactor.ToString())
End Sub
Private Sub _showFormButton_Click(sender As Object, e As EventArgs)
Dim form As Form = New ZoomForm()
form.Show()
End Sub
Private Sub InitializeComponent()
_showFormButton = New Button()
_showFormButton.Text = "Click to open a new form"
_showFormButton.Location = New Point(20, 20)
_showFormButton.Size = New Size(200, 40)
Me.Controls.Add(_showFormButton)
End Sub
End Class
Friend Class NormalForm
Inherits Form
Private _showFormButton As Button
Public Sub New()
InitializeComponent()
AddHandler _showFormButton.Click, AddressOf _showFormButton_Click
End Sub
Private Sub _showFormButton_Click(sender As Object, e As EventArgs)
Dim form As Form = New NormalForm()
form.Show()
End Sub
Private Sub InitializeComponent()
_showFormButton = New Button()
_showFormButton.Text = "Click to open a new form"
_showFormButton.Location = New Point(20, 20)
_showFormButton.Size = New Size(200, 40)
Me.Controls.Add(_showFormButton)
End Sub
End Class
Name | Description |
---|---|
C1ApplicationZoom() | Initializes a new instance of the C1ApplicationZoom class. |
C1ApplicationZoom(IContainer) | Initializes a new instance of the C1ApplicationZoom class. |
Name | Description |
---|---|
AllowDoubleTapZoom | Gets or sets a value indicating whether allow double tap to zoom. ZoomFactor will change to 2f or MaxZoomFactor if it is less than 2f before double tap; otherwise, it will change to 1f. |
AllowMouseWheelScroll | Gets or sets which types of MouseWheel scroll are possible. |
AllowMouseWheelZoom | Gets or sets a value indicating whether allow zoom by control + mouse wheel. |
AllowPanScroll | Gets or sets a value indicating whether allow scroll the form by pan gesture. |
AllowPinchZoom | Gets or sets a value indicating whether the form can perform gesture zoom. |
AllowResizeByZoom | Gets or sets a value that indicates whether resize form when zooming form. |
AllowZoomByResize | Gets or sets a value that indicates whether zoom form when resizing form. |
AlternativeContentSettings | Gets the settings indicating how to display zoom factor when gesture zooming. |
AutoShowControl | Gets or sets a value that indicates whether the control auto show when get focus or touch keyboard popup. |
BackColor | Gets or sets the background color of blank areas in Form when to zoom and scroll. |
BackgroundImage | Gets or sets the background image displayed in the blank areas of Form when to zoom and scroll. |
BackgroundImageLayout | Gets or sets the background image layout as defined in the ImageLayout enumeration. |
BoundaryFeedbackMode | Gets or sets a value indicating how to show visual feedback when scroll reach end point. |
ControlBars | Gets the collection of ControlBar contained within the C1Zoom. |
DefaultZoomPolicies | Gets the default zoom policies. |
FullScreenMode | Gets or sets the full screen mode used by owner form. |
InnerPanelLayoutMode | Gets or sets the layout mode of InnerPanel. |
IsHorizontalRailEnabled | Gets or sets a value that indicates whether the scroll rail is enabled for the horizontal axis. |
IsVerticalRailEnabled | Gets or sets a value that indicates whether the scroll rail is enabled for the vertical axis. |
KeepAspectRatio | Gets or sets a value indicating whether to keep aspect ratio when resize the form. |
MaxZoomFactor | Gets or sets the maximum zoom factor of the form. |
ScrollIndicatorMode | Gets or sets a value indicating which mode to indicate current scroll location. |
ZoomPolicies | Gets the custom zoom policies. C1Zoom will look for zoom policies in this list. |
ZoomPreviewMode | Gets or sets a value indicating how to preview the form when gesture zooming. |
ZoomSnapDistance | Gets or sets a value indicate the minimum distance that can cause current zoom factor snap to a zoom factor in ZoomSnapPoints. |
ZoomSnapPoints | Gets a group of zoom factor, when zoom ending, the result zoom factor will try to snap to a zoom factor in this group. |
Name | Description |
---|---|
AboutBox() | Shows the product information window. |
Dispose(bool) | Releases the unmanaged resources used by the Component and optionally releases the managed resources. |
GetC1Zoom(Form) | Gets the associated C1Zoom by a specific form. |
OnC1ZoomAttached(C1ZoomAttachedEventArgs) | Raises the C1ZoomAttached event. |
OnC1ZoomAttaching(C1ZoomAttachingEventArgs) | Raises the C1ZoomAttaching event. |
OnC1ZoomDetached(C1ZoomDetachedEventArgs) | Raises the C1ZoomDetached event. |
Name | Description |
---|---|
C1ZoomAttached | |
C1ZoomAttaching | Occurs when the C1Zoom component is preparing attach to a Form. |
C1ZoomDetached |