473,508 Members | 2,226 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MouseDown-Drag-MouseUp Screen capturing routine

Does anyone know where there is some sample code that explains now a user;
using the mouse can click on an image on the screen. Capture the image by
boxing it in using the mouse and then save it to a bitmap or onto another
form?

Thank you
--
Mark
Nov 30 '07 #1
2 1906
Mark,

I thought that this one was forever in the 101 samples from Microsoft, maybe
you can check yourself if that is still there. Using that is your problem
quiet simple.

(The basic of this is that you save your position by mouse down to check
were it was at mouse up)

The static keyword is very fine for that.

Cor

Dec 1 '07 #2
Mark,

Maybe you can use this, I got it once from Fergus Cooney and changed it, the
purpose was to do things with images, which was then not yet in standard
programs.

It is used as a class for a form with images, however I think it is better
that you find that for yourself.

\\\
Public Class Enlarger
Private Shared EnlargerRectangle As Rectangle
Private Shared mVertical As Boolean
Private Shared imgHeight As Integer
Private Shared imgWidth As Integer
Private Shared LastMouseX As Integer
Private Shared LastMouseY As Integer
Public Shared ReadOnly Property Vertical() As Boolean
Get
Return mVertical
End Get
End Property
Public Shared ReadOnly Property Rectangle() As Rectangle
Get
Return EnlargerRectangle
End Get
End Property
Public Shared Sub Initialize(ByVal clientRectangle As Rectangle)
EnlargerRectangle = clientRectangle
imgHeight = EnlargerRectangle.Height
imgWidth = EnlargerRectangle.Width
If imgHeight < imgWidth Then
mVertical = True 'reverse because of next action
Else
mVertical = False
End If
End Sub
Public Shared Sub setOrientation()
If mVertical Then
mVertical = False
Dim testhight As Integer
If imgWidth imgHeight * 2 / 3 Then
testhight = imgWidth * 2 / 3
Else
testhight = imgHeight
End If
Dim NewWidth = testhight * 3 / 2
Enlarger.Reset(NewWidth, testhight)
Else
'It has to be vertical
mVertical = True
Dim testwidth As Integer
If imgWidth imgHeight * 2 / 3 Then
testwidth = imgHeight * 2 / 3
Else
testwidth = imgWidth
End If
Dim NewHight = testwidth * 3 / 2
Enlarger.Reset(testwidth, NewHight)
End If
End Sub
Private Shared Sub Reset(ByVal width As Integer, ByVal hight As Integer)
EnlargerRectangle.Location = New Point(0, 0)
EnlargerRectangle.Width = width
EnlargerRectangle.Height = hight
End Sub
Public Shared Sub move(ByVal curMouseX As Integer, ByVal curMouseY As
Integer, ByVal imgTopLeft As Point)
Dim newX As Integer = EnlargerRectangle.X
Dim newY As Integer = EnlargerRectangle.Y
Dim newHeight As Integer = EnlargerRectangle.Height
Dim newWidth As Integer = EnlargerRectangle.Width
If (Control.ModifierKeys And Keys.Control) Then
newWidth = EnlargerRectangle.Width + (curMouseX - LastMouseX)
If newWidth < 10 Then
newWidth = 10
End If
If newWidth imgWidth Then
newWidth = imgWidth
End If
If mVertical Then
newHeight = (newWidth * 3) \ 2
If newHeight imgHeight Then
newHeight = imgHeight
newWidth = (newHeight * 2) \ 3
End If
Else
newHeight = (newWidth * 2) \ 3
If newHeight imgHeight Then
newHeight = imgHeight
newWidth = (newHeight * 3) \ 3
End If
End If
Else
newX += (curMouseX - LastMouseX) 'step
newY += (curMouseY - LastMouseY) 'step
If newX < 0 Then
newX = 0
End If
If newY < 0 Then
newY = 0
End If
If newX + EnlargerRectangle.Width imgWidth Then
newX = imgWidth - EnlargerRectangle.Width
End If
If newY + EnlargerRectangle.Height imgHeight Then
newY = imgHeight - EnlargerRectangle.Height
End If
End If
EnlargerRectangle = New Rectangle(newX, newY, newWidth, newHeight)
Mousedown(imgTopLeft)
End Sub
Public Shared Sub Mousedown(ByVal imgTopLeft As Point)
LastMouseX = EnlargerRectangle.X + EnlargerRectangle.Width - 30
LastMouseY = EnlargerRectangle.Y + EnlargerRectangle.Height - 30
Cursor.Position = New Point(imgTopLeft.X + LastMouseX, imgTopLeft.Y
+ LastMouseY)
End Sub
End Class
///

Cor

Dec 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4374
by: Deborah V. Gardner | last post by:
I have a list box and would like to point to an item and have a textbox popup referencing a column in the list box. On the list box's MouseDown event I have the following Dim strFullText ...
2
16289
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
7
8096
by: Scott Mackay | last post by:
Hi, I'm using visual studio dotnet 2002 programming in vb can anyone tell me how I can handle the mousedown event for pictureboxes I create dynamically at runtime? I've tried setting the...
4
4725
by: rsmith | last post by:
How can I capture the MouseDown event on a Label ? I entered thr following code and got a " cannot handle Event 'MouseDown' because they do not have the same signature." Private Sub...
1
1572
by: Merlin | last post by:
I have created a UserControl which has a label; what I wish to do is place this UserControl on a form and then trap the Mouse Down event, whenever someone clicks my control. My problem is that the...
2
6402
by: active | last post by:
In VB6 I believe MouseDown had a Shift argument that told if Shift, Ctrl or Alt was pressed. How in VB.NET MouseDown do I determine if one of these keys is pressed? I could increment a global...
4
3039
by: active | last post by:
I can use Control.ModifierKeys to determine if a modifying key is pressed when executing MouseDown event, but how can I determine if an "M" was pressed?? Possible? Can't find a clue in...
2
3555
by: Rob | last post by:
How can I fix the following warning warning BC40004: sub 'MouseDown' conflicts with event 'MouseDown' in the base class 'Control' and so should be declared 'Shadows'. This warning appears...
7
1879
by: Doc John | last post by:
I created a non-rectangular Windows Form which opens inside of an MDI container and I'm managing the MouseMove and MouseDown events with the following code. The problem is that when I click on the...
2
3007
by: lmefford | last post by:
Is there a way to modify all textboxes on a form so that when you click on any of them you process the SelectAll() function. For exaple, let's say I've created a form with 30 textboxes. These...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.