Results 1 to 4 of 4

Thread: Whats wrong with this?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    9

    Whats wrong with this?

    This is the error message given when i try and draw a rectangle

    An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll

    Additional information: Invalid parameter used.

    I get an error from this code:

    Private Sub picBoard_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picImage.MouseMove
    If isDragging Then
    Dim gr As Graphics = picImage.CreateGraphics
    gr.Clear(picImage.BackColor)

    Dim rect As New Rectangle(startX, startY, e.X - startX, e.Y - startY)
    gr.DrawRectangle(Pens.Red, rect)
    gr.FillRectangle(Brushes.Transparent, rect)
    Dim bmpCropped As New Bitmap(e.X - startX, e.Y - startY)

    Dim grBitmap As Graphics = Graphics.FromImage(bmpCropped)

    grBitmap.DrawImage(picImage.Image, 0, 0, rect, _
    GraphicsUnit.Pixel)
    picImage.Image = bmpCropped
    picImage.SizeMode = PictureBoxSizeMode.Normal
    gr.Dispose()
    End If
    End Sub


    This is supposed to crop the image from the rectangle drawn.
    the error is from this line of code because it accepts invalid inputs i think.

    Dim bmpCropped As New Bitmap(e.X - startX, e.Y - startY)

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Are you sure the dimensions of the bitmap you are trying to create won't become negative? Try using absolute values of e.X - startX and e.Y - startY
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    9
    Originally posted by Lunatic3
    Are you sure the dimensions of the bitmap you are trying to create won't become negative? Try using absolute values of e.X - startX and e.Y - startY
    How do i use absolute values?

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Use Math.Abs method.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width