Skip to content

Commit

Permalink
Draw signature using DrawCurve and a list of points
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Lozano Vilanova committed Apr 18, 2022
1 parent a051e7a commit ebbba0c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Binary file modified PDFeSignHandwritten/.vs/PDFeSignHandwritten/v16/.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions PDFeSignHandwritten/fSign.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions PDFeSignHandwritten/fSign.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace PDFeSignHandwritten
{
public partial class fSign : Form
{
Point lastPoint = Point.Empty;
List<List<Point>> lstPoints = new List<List<Point>>();
bool isMouseDown;
Pen pen;

public bool sign;

Expand Down Expand Up @@ -56,11 +57,15 @@ public fSign()
cboPenColor.DropDownStyle = ComboBoxStyle.DropDownList;
cboPenColor.DrawItem += cboPenColor_DrawItem;

Color c = (Color)cboPenColor.Items[0];
for (int i = 0; i < cboPenColor.Items.Count - 1; i++)
{
Color c = (Color)cboPenColor.Items[i];
c = (Color)cboPenColor.Items[i];
if (c.Name == "Blue")
{
cboPenColor.SelectedIndex = i;
break;
}
}

for (int i = 1; i <= 10; i++)
Expand All @@ -71,6 +76,8 @@ public fSign()
cboPenWidth.DrawMode = DrawMode.OwnerDrawFixed;
cboPenWidth.DrawItem += cboPenWidthOnDrawItem;

AdjustPen();

sign = false;
}

Expand Down Expand Up @@ -108,34 +115,31 @@ private void cboPenColor_DrawItem(object sender, DrawItemEventArgs e)

private void picSign_MouseDown(object sender, MouseEventArgs e)
{
lastPoint = e.Location;
lstPoints.Add(new List<Point>());
isMouseDown = true;
}

private void picSign_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
if (lastPoint != Point.Empty)
if (e.Location != Point.Empty)
{
lstPoints.Last().Add(e.Location);

using (Graphics g = Graphics.FromImage(picSign.Image))
{
Color c = Color.Blue;
if (cboPenColor.SelectedIndex >= 0)
c = (Color)cboPenColor.SelectedValue;
g.DrawLine(new Pen(c, (int)cboPenWidth.SelectedItem), lastPoint, e.Location);
g.SmoothingMode = SmoothingMode.AntiAlias;
if (lstPoints.Last().Count>1)
g.DrawCurve(pen, lstPoints.Last().ToArray());
}
picSign.Invalidate();
lastPoint = e.Location;
}
}
}

private void picSign_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
lastPoint = Point.Empty;
}

private void bttSign_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -226,5 +230,21 @@ static public void fillPictureBox(PictureBox pbox, Bitmap bmp)

pbox.Image = resized;
}

private void AdjustPen()
{
if (cboPenColor.SelectedItem != null && cboPenWidth.SelectedItem != null)
pen = new Pen((Color)cboPenColor.SelectedItem, (int)cboPenWidth.SelectedItem);
}

private void cboPenWidth_SelectedIndexChanged(object sender, EventArgs e)
{
AdjustPen();
}

private void cboPenColor_SelectedValueChanged(object sender, EventArgs e)
{
AdjustPen();
}
}
}

0 comments on commit ebbba0c

Please sign in to comment.