how to make a drawing area?

hi
I was wondering if anyone have a link to a tutorial or knows how to implement a drawing area, where the users can draw (or have drawn comments) on a particular area in the form, and then capture that area and save it to a file (Or database)

I'm not sure if OpenNETCF can do it, if so what should I be using

Thanks alot


Answer this question

how to make a drawing area?

  • Luo Cao

    You can use panel as a paper and use system.drawing (you need to add system.drawing component)

    Private Sub panel1_Paint(ByVal sender As System.Object, ByVal e As PaintEventArgs) Handles penal1.Paint

    e.Graphics.DrawImage(Me.bitmap, 0, 0)

    End Sub

    Private Sub panel1_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles panel1.MouseDown

    Me.hasCapture = True

    Me.oldX = e.X

    Me.oldY = e.Y

    End Sub

    Private Sub penal1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles penal1.MouseMove

    Dim x, y As Integer

    If Me.hasCapture Then

    x = e.X

    y = e.Y

    ' Draw line from last hit point to current hit point

    Graphics.FromImage(bitmap).DrawLine(New Pen(Me.currentColorPanel.BackColor), Me.oldX, Me.oldY, x, y)

    Me.pDrawWindow.Invalidate(New Rectangle(Math.Min(x, Me.oldX), Math.Min(y, Me.oldY), Math.Abs(Me.oldX - x) + 1, Math.Abs(Me.oldY - y) + 1))

    Me.oldX = x

    Me.oldY = y

    End If

    End Sub

    Private Sub panel1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles penal1.MouseUp

    Me.hasCapture = False

    End Sub


  • eroe

    Thanks for your code.
    I was wondering if anyone has C# code for that
    I tried to convert your example into C# and I had trouble understanding what you mean by pDrawWindow I tried calling the invalidate method on both the form and the panel but nothing comes up.
    thanks

       
    public partial class Form2 : Form
        {
            private Image bitmap = new Bitmap(10, 10);
            private bool hasCapture;
            private int oldX = 0;
            private int oldY = 0;
            public Form2()
            {
                InitializeComponent();

            }

            private void panel1_Paint(object sender, PaintEventArgs e)
            {
                e.Graphics.DrawImage(bitmap, 0, 0);
            }

            private void panel1_MouseDown(object sender, MouseEventArgs e)
            {
                hasCapture = true;
                oldX = e.X;
                oldY = e.Y;

            }

            private void panel1_MouseMove(object sender, MouseEventArgs e)
            {
                int x, y;
                if (hasCapture)
                {
                    x = e.X;
                    y = e.Y;
                  
                    Graphics.FromImage(bitmap).DrawLine(new Pen(Color.Black), oldX, oldY, x, y);
                    panel1.Invalidate(new Rectangle(Math.Min(x, oldX), Math.Min(y, oldY), Math.Abs(oldX - x) + 1, Math.Abs(oldY - y) + 1));

                    oldX = x;
                    oldY = y;

                }
            }

            private void panel1_MouseUp(object sender, MouseEventArgs e)
            {
                hasCapture = false;
            }
        }

  • anisxahmed

    How about using the InkX
    I was wondering if anyone could provide information about how to create it.

    ps: I tried to drop the control on the form, however nothing comes up when deployed! I assume there is steps that I have to follow in order to make it work

    I'm already using SDF 2.0 of the OpenNETCF


  • shai

    The SDF 1.4 has the Signature control, that you can use as a starting point for your needs.


  • Alexei_shk

    Its working fine now

    just changed the "pDrawWindow" to be the panel.

    thanks for help

  • how to make a drawing area?