Signature
Namespace: Wisej.Web.Ext.Signature
Assembly: Wisej.Web.Ext.Signature (4.1.0.0)
Signature is a simple control for drawing and exporting user signatures.
- C#
- VB.NET
public class Signature : Control
Public Class Signature
Inherits Control
The user draws on an HTML canvas using the mouse, pen or touch. The drawing, and the undo/redo history, exist only on the client: use GetImageAsync to retrieve the signature as an image and Load to display a saved signature. The SignatureChange event is fired every time the user draws a stroke or a dot, and when the control is cleared or an action is undone or redone.
Example:
Saving the signature entered by the user:
private async void buttonSave_Click(object sender, EventArgs e)
{
if (await this.signature1.IsEmptyAsync())
{
AlertBox.Show("Please sign before continuing.");
return;
}
var image = await this.signature1.GetImageAsync();
image.Save(Application.MapPath("~/Signatures/order-1234.png"), System.Drawing.Imaging.ImageFormat.Png);
}
Constructors
Signature()
Initializes a new instance of Signature.
Properties
BorderStyle
BorderStyle: Returns or sets the border style of the signature. (Default: None)
Value: One of the BorderStyle values. The default is Solid.
LineColor
Color: Returns or sets the signature line color.
The default is Black. The color applies to the strokes drawn after it has been changed; existing strokes keep their color.
LineWidth
Int32: Returns or sets the signature line width, in pixels.
The default is 1. The width applies to the strokes drawn after it has been changed. A single tap draws a dot with a radius equal to the line width.
ReadOnly
Boolean: Returns or sets whether the control is read only.
When true, the user cannot draw on the control. The signature can still be changed in code using Clear, Load, Undo and Redo.
Methods
CanRedoAsync()
Asynchronously checks whether there is an undone action that can be redone.
Returns: Task<Boolean>. A task that completes with true if Redo can restore an undone action.
The history is kept on the client. It's reset when the user draws a new stroke after undoing an action.
Example:
Enabling the redo button after the signature changes:
private async void signature1_SignatureChange(object sender, EventArgs e)
{
this.buttonRedo.Enabled = await this.signature1.CanRedoAsync();
}
CanUndoAsync()
Asynchronously checks whether there is a user action that can be undone.
Returns: Task<Boolean>. A task that completes with true if Undo can remove the last action.
Only the strokes drawn by the user are recorded in the history; Clear and Load are not.
Example:
Enabling the undo button after the signature changes:
private async void signature1_SignatureChange(object sender, EventArgs e)
{
this.buttonUndo.Enabled = await this.signature1.CanUndoAsync();
}
Clear()
Clears the Signature control.
Fires the SignatureChange event. Clearing is not recorded in the undo history and it doesn't reset it.
Example:
Clearing the signature from a button:
private void buttonClear_Click(object sender, EventArgs e)
{
this.signature1.Clear();
}
GetImageAsync()
Asynchronously retrieves an image of the signature.
Returns: Task<Image>. A task that completes with a Bitmap of the signature.
The image is exported from the client canvas as a PNG with a transparent background and it has the size of the canvas in pixels.
Example:
Showing the signature in a PictureBox:
private async void buttonPreview_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = await this.signature1.GetImageAsync();
}
IsEmptyAsync()
Asynchronously checks whether the signature is empty.
Returns: Task<Boolean>. A task that completes with true if the signature is empty.
The signature is considered empty when all the pixels of the canvas are fully transparent. After an image has been loaded with Load, the signature is not empty.
Example:
Validating the signature before submitting a form:
private async void buttonSubmit_Click(object sender, EventArgs e)
{
if (await this.signature1.IsEmptyAsync())
MessageBox.Show("The signature is required.");
else
SubmitOrder();
}
Load(image)
Loads the given image into the signature control.
| Parameter | Type | Description |
|---|---|---|
| image | Image | The image to load. |
The image is sent to the client as a PNG data URL and drawn asynchronously at its original size in the top-left corner of the canvas, on top of the current content. Call Clear first to replace the current signature. Loading an image doesn't fire the SignatureChange event and it's not recorded in the undo history.
Example:
Displaying a previously saved signature in read-only mode:
this.signature1.ReadOnly = true;
this.signature1.Clear();
this.signature1.Load(Image.FromFile(Application.MapPath("~/Signatures/order-1234.png")));
OnWebRender(config)
| Parameter | Type | Description |
|---|---|---|
| config | Object |
OnWidgetEvent(e)
| Parameter | Type | Description |
|---|---|---|
| e | WidgetEventArgs |
Redo()
Redoes the last action undone by Undo.
Nothing happens if there is no action to redo. Fires the SignatureChange event.
Example:
Redoing the last undone stroke:
private void buttonRedo_Click(object sender, EventArgs e)
{
this.signature1.Redo();
}
Undo()
Undoes the last stroke or dot drawn by the user.
Nothing happens if there is no action to undo. Fires the SignatureChange event.
Example:
Removing the last stroke:
private void buttonUndo_Click(object sender, EventArgs e)
{
this.signature1.Undo();
}
Events
SignatureChange
EventHandler Fires when the signature changes.