Using MouseMove in a PictureBox to enter i.e a signature on a touch screen.

Is there an example program available which catches the MouseMove event in a PictureBox to draw a line following the movement and allowing this to be saved as a bitmap. I've seen examples in C# but my knowledge of a possible translation to COBOL is inadequate.

Can somebody help me on this?

Regards

Rainer

Parents
  • Verified Answer

    Here is an example in a Windows Forms application:

           class-id savesignature.Form1 is partial
                     inherits type System.Windows.Forms.Form.
           
           working-storage section.
           01 prevLocation type Point value null.
           method-id NEW.
           procedure division.
               invoke self::InitializeComponent
               goback.
           end method.
    
           method-id pictureBox1_MouseDown final private.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
              set prevLocation to e::Location
              invoke self::pictureBox1_MouseMove(sender, e)
              
           end method.
    
           method-id pictureBox1_MouseMove final private.
           01 bmp type Bitmap.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
           
               if (PrevLocation not = null)
                  if (pictureBox1::Image = null)
                     set bmp to new Bitmap(pictureBox1::Width, pictureBox1::Height)
                        perform using g as type Graphics = type Graphics::FromImage(bmp)
                           invoke g::Clear(type Color::White)
                        end-perform
                     set pictureBox1::Image to bmp
                   end-if
                   perform using g as type Graphics = type Graphics::FromImage(pictureBox1::Image)
                      invoke g::DrawLine(type Pens::Black, prevLocation::X, prevLocation::Y, e::X, e::Y)
                   end-perform
                   invoke pictureBox1::Invalidate
                   set PrevLocation to e::Location
                end-if
    
           end method.
    
           method-id pictureBox1_MouseUp final private.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
               set prevLocation to null.
           end method.
    
           method-id button1_Click final private.
           01 bmp type Bitmap.
           procedure division using by value sender as object e as type System.EventArgs.
           
               set bmp to new type Bitmap(PictureBox1::Width, PictureBox1::Height)
               invoke PictureBox1::DrawToBitmap(bmp, PictureBox1::ClientRectangle)
               invoke bmp::Save("c:\\temp\mysignature.jpg", type System.Drawing.Imaging.ImageFormat::Jpeg)
        
           end method.
          
           end class.
    
Reply
  • Verified Answer

    Here is an example in a Windows Forms application:

           class-id savesignature.Form1 is partial
                     inherits type System.Windows.Forms.Form.
           
           working-storage section.
           01 prevLocation type Point value null.
           method-id NEW.
           procedure division.
               invoke self::InitializeComponent
               goback.
           end method.
    
           method-id pictureBox1_MouseDown final private.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
              set prevLocation to e::Location
              invoke self::pictureBox1_MouseMove(sender, e)
              
           end method.
    
           method-id pictureBox1_MouseMove final private.
           01 bmp type Bitmap.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
           
               if (PrevLocation not = null)
                  if (pictureBox1::Image = null)
                     set bmp to new Bitmap(pictureBox1::Width, pictureBox1::Height)
                        perform using g as type Graphics = type Graphics::FromImage(bmp)
                           invoke g::Clear(type Color::White)
                        end-perform
                     set pictureBox1::Image to bmp
                   end-if
                   perform using g as type Graphics = type Graphics::FromImage(pictureBox1::Image)
                      invoke g::DrawLine(type Pens::Black, prevLocation::X, prevLocation::Y, e::X, e::Y)
                   end-perform
                   invoke pictureBox1::Invalidate
                   set PrevLocation to e::Location
                end-if
    
           end method.
    
           method-id pictureBox1_MouseUp final private.
           procedure division using by value sender as object e as type System.Windows.Forms.MouseEventArgs.
               set prevLocation to null.
           end method.
    
           method-id button1_Click final private.
           01 bmp type Bitmap.
           procedure division using by value sender as object e as type System.EventArgs.
           
               set bmp to new type Bitmap(PictureBox1::Width, PictureBox1::Height)
               invoke PictureBox1::DrawToBitmap(bmp, PictureBox1::ClientRectangle)
               invoke bmp::Save("c:\\temp\mysignature.jpg", type System.Drawing.Imaging.ImageFormat::Jpeg)
        
           end method.
          
           end class.
    
Children
No Data