/******************************
* 说明:电子签名
* 创建人:龚宇超
* 创建日期: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
{
///
/// 电子签名
///
public partial class SignControlEx : UserControl
{
///
/// 记录直线或者曲线的对象
///
private System.Drawing.Drawing2D.GraphicsPath _mousePath = new System.Drawing.Drawing2D.GraphicsPath();
///
/// 画笔透明度
///
private int _alpha = 100;
///
/// 画笔颜色对象
///
private Color _userColor = new Color();
///
/// 画笔宽度
///
private int _penWidth = 10;
///
/// 签名的图片对象
///
public Bitmap SignBitmap;
///
/// 签名绘画完成
///
public event EventHandler OnSignOkCallBack;
public SignControlEx()
{
InitializeComponent();
}
///
/// 说明:设置画笔宽度
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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);
}
}
///
/// 说明:鼠标按下记录
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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);
}
}
///
/// 说明:鼠标移动绘画
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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);
}
}
///
/// 说明:重绘显示
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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 {
}
}
///
/// 说明:确定
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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);
}
}
///
/// 说明:清空绘画
/// 创建人:龚宇超
/// 创建日期:2018-05-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
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);
}
}
}
}