You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.8 KiB

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace EC.AutoWeightServer.UI
{
public partial class FrmSign : Form
{
private GraphicsPath mousePath = new GraphicsPath();
//画笔透明度
private int myAlpha = 100;
//画笔颜色对象
private Color myUserColor = new Color();
//画笔宽度
private int myPenWidth = 5;
//签名的图片对象
public Bitmap SavedBitmap;
public bool isSign = false;
public FrmSign()
{
InitializeComponent();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
try
{
mousePath.AddLine(e.X, e.Y, e.X, e.Y);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
pictureBox1.Invalidate();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isSign = true;
mousePath.StartFigure();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
try
{
myUserColor = System.Drawing.Color.Blue;
myAlpha = 255;
Pen CurrentPen = new Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth);
e.Graphics.DrawPath(CurrentPen, mousePath);
}
catch { }
}
private void btnClear_Click(object sender, EventArgs e)
{
isSign = false;
pictureBox1.CreateGraphics().Clear(Color.White);
mousePath.Reset();
}
private void btnOk_Click(object sender, EventArgs e)
{
SavedBitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(SavedBitmap, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
}