|
-
Feb 15th, 2004, 06:51 AM
#1
Thread Starter
New Member
Mouse clicking
I'm trying to store the coordinates of where the left mouse button is clicked.
the button will be clicked in a picture box, and then these coordinates will be used to draw a rectangle on the screen.
so far i know that i can use e.X and e.Y to get the position.
-
Feb 16th, 2004, 10:04 AM
#2
Sleep mode
VB Code:
Dim Coordinates As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button.Left Then
Coordinates = New Point(e.X, e.Y)
'or
Coordinates = New Point(MousePosition.X, MousePosition.Y)
End If
End Sub
-
Feb 16th, 2004, 05:14 PM
#3
something like this... too many flickers though 
VB Code:
Private startX, startY As Integer
Private isDragging As Boolean = False
Private Sub picBoard_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoard.MouseDown
startX = e.X
startY = e.Y
isDragging = True
End Sub
Private Sub picBoard_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoard.MouseMove
If isDragging Then
Dim gr As Graphics = picBoard.CreateGraphics
gr.Clear(picBoard.BackColor)
Dim rect As New Rectangle(startX, startY, e.X - startX, e.Y - startY)
gr.FillRectangle(Brushes.Blue, rect)
gr.DrawRectangle(Pens.Red, rect)
gr.Dispose()
End If
End Sub
Private Sub picBoard_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBoard.MouseUp
isDragging = False
End Sub
picBoard is the picturebox
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 17th, 2004, 06:56 AM
#4
Thread Starter
New Member
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)
-
Feb 17th, 2004, 03:27 PM
#5
Originally posted by ryans
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)
what is the error message first of all?
second, I would guess that e.X is smaller than startX, or the same thing about e.y (meaning you dragged the mouse up, or left, while that code only works when you drag the mouse down or to the right). If it's the case they you're basically asking .NET to create a bitmap with a negative size, which doesnt make sense... you just have to switch the variables around depending on what the user does
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Feb 18th, 2004, 01:27 PM
#6
Thread Starter
New Member
Error message
Originally posted by MrPolite
what is the error message first of all?
second, I would guess that e.X is smaller than startX, or the same thing about e.y (meaning you dragged the mouse up, or left, while that code only works when you drag the mouse down or to the right). If it's the case they you're basically asking .NET to create a bitmap with a negative size, which doesnt make sense... you just have to switch the variables around depending on what the user does
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|