229 lines
7.8 KiB
C#
229 lines
7.8 KiB
C#
/******************************
|
|
* 说明:电子签名
|
|
* 创建人:龚宇超
|
|
* 创建日期:2018-05-16
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Lskj.Business.Impl;
|
|
|
|
namespace Lskj.Control
|
|
{
|
|
/// <summary>
|
|
/// 电子签名
|
|
/// </summary>
|
|
public partial class SignControlEx : UserControl
|
|
{
|
|
/// <summary>
|
|
/// 记录直线或者曲线的对象
|
|
/// </summary>
|
|
private System.Drawing.Drawing2D.GraphicsPath _mousePath = new System.Drawing.Drawing2D.GraphicsPath();
|
|
/// <summary>
|
|
/// 画笔透明度
|
|
/// </summary>
|
|
private int _alpha = 100;
|
|
/// <summary>
|
|
/// 画笔颜色对象
|
|
/// </summary>
|
|
private Color _userColor = new Color();
|
|
/// <summary>
|
|
/// 画笔宽度
|
|
/// </summary>
|
|
private int _penWidth = 10;
|
|
|
|
/// <summary>
|
|
/// 签名的图片对象
|
|
/// </summary>
|
|
public Bitmap SignBitmap;
|
|
/// <summary>
|
|
/// 签名绘画完成
|
|
/// </summary>
|
|
public event EventHandler OnSignOkCallBack;
|
|
|
|
public SignControlEx()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:设置画笔宽度</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void textEdit1_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
int penWidth = _penWidth;
|
|
if (Int32.TryParse(this.textEdit1.Text, out penWidth))
|
|
penWidth = Convert.ToInt32(this.textEdit1.Text);
|
|
|
|
this._penWidth = penWidth;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标按下记录</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void pictureEdit1_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Button == System.Windows.Forms.MouseButtons.Left)
|
|
{
|
|
try
|
|
{
|
|
_mousePath.AddLine(e.X, e.Y, e.X, e.Y);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageUtil.Show(ex);
|
|
}
|
|
}
|
|
pictureEdit1.Invalidate();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标移动绘画</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void pictureEdit1_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.Button == System.Windows.Forms.MouseButtons.Left)
|
|
{
|
|
_mousePath.StartFigure();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重绘显示</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
|
|
private void pictureEdit1_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this._userColor = System.Drawing.Color.Blue;
|
|
this._alpha = 255;
|
|
|
|
Pen pen = new Pen(Color.FromArgb(_alpha, _userColor), _penWidth);
|
|
e.Graphics.DrawPath(pen, _mousePath);
|
|
}
|
|
catch {
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:确定</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnOk_Click (object sender, EventArgs e)
|
|
{
|
|
try {
|
|
this.SignBitmap = new Bitmap(pictureEdit1.Width, pictureEdit1.Height);
|
|
this.pictureEdit1.DrawToBitmap(SignBitmap, new Rectangle(0, 0, SignBitmap.Width, SignBitmap.Height));
|
|
|
|
if (this.OnSignOkCallBack != null)
|
|
this.OnSignOkCallBack(SignBitmap, e);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:清空绘画</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-05-16 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
try {
|
|
using (Graphics graphics = pictureEdit1.CreateGraphics())
|
|
{
|
|
graphics.Clear(Color.White);
|
|
}
|
|
_mousePath.Reset();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message,ex.Message);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|