Skip to main content

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.

public class Signature : 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​

Instance member Signature()​

Initializes a new instance of Signature.

Properties​

Instance member BorderStyle​

BorderStyle: Returns or sets the border style of the signature. (Default: None)

Value: One of the BorderStyle values. The default is Solid.

Instance member 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.

Instance member 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.

Instance member 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​

Instance member 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();
}

Instance member 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();
}

Instance member 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();
}

Instance member 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();
}

Instance member 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();
}

Instance member Load(image)​

Loads the given image into the signature control.

ParameterTypeDescription
imageImageThe 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")));

Protected member OnWebRender(config)​

ParameterTypeDescription
configObject

Protected member OnWidgetEvent(e)​

ParameterTypeDescription
eWidgetEventArgs

Instance member 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();
}

Instance member 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​

Instance member SignatureChange​

EventHandler Fires when the signature changes.

Implements​