Bonjour, j'ai un logiciel pour prendre des captures d'écran, j'utilise ce code pour selectionner la zone mais je ne peux selectionner que vers en bas a droite et je voudrais pouvoir draw mon rectangle dans tout les sens. J'ai cherché dans le code et sur internet mais j'ai rien trouvé..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Imports System.Runtime.InteropServices
 
Public Class frmSS
    Private Declare Auto Function BitBlt Lib "gdi32.dll" ( _
     ByVal hdcDest As IntPtr, _
     ByVal nXDest As Integer, _
     ByVal nYDest As Integer, _
     ByVal nWidth As Integer, _
     ByVal nHeight As Integer, _
     ByVal hdcSrc As IntPtr, _
     ByVal nXSrc As Integer, _
     ByVal nYSrc As Integer, _
     ByVal dwRop As Int32) As Boolean
    <DllImport("user32.dll")> _
    Public Shared Function GetAsyncKeyState(ByVal vKey As Int32) As Short
    End Function
    Private Declare Auto Function GetDC Lib "user32.dll" (ByVal hWnd As IntPtr) As IntPtr
    Private Declare Auto Function ReleaseDC Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As IntPtr
 
    Private Sub frmSS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1
        Timer1.Enabled = True
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.Location = New Point(0, 0)
        Me.ClientSize = Screen.GetBounds(Me).Size
        Me.BackColor = Color.Gray
        Me.DoubleBuffered = True
        Me.Opacity = 0.4#
        Me.Cursor = Cursors.Cross
        Me.ShowInTaskbar = False
    End Sub
 
    Private isDragging As Boolean = False
    Private canDrag As Boolean = True
    Private pt_start As Point = Point.Empty
    Private pt_end As Point = Point.Empty
 
    Private Sub frmSS_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If Me.canDrag Then
            Me.isDragging = True
            Me.pt_start = e.Location
        End If
        If e.Button = MouseButtons.Right Then
            If Me.isDragging = True Then
                Me.isDragging = False
                Me.pt_start = e.Location
                Me.pt_end = e.Location
                Me.Refresh()
            End If
        End If
    End Sub
 
    Private Sub frmSS_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If Me.isDragging Then
            Me.pt_end = e.Location
            Me.Invalidate()
        End If
    End Sub
 
    Private Sub frmSS_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        If Me.isDragging Then
            Me.isDragging = False
            Me.canDrag = False
            Me.Cursor = Cursors.Default
            Dim r As Rectangle = Me.SelectedRectangle
            Me.Hide()
            Application.DoEvents()
            Me.CaptureThisArea(r)
            Me.Close()
        End If
    End Sub
 
    Private ReadOnly Property SelectedRectangle() As Rectangle
        Get
            With pt_start
                If .X >= pt_end.X OrElse .Y >= pt_end.Y Then Return Rectangle.Empty
                Return New Rectangle(.X, .Y, pt_end.X - .X, pt_end.Y - .Y)
            End With
        End Get
    End Property
 
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
 
        Using p As New Pen(Color.Black, 3)
            p.DashStyle = Drawing2D.DashStyle.Dash
            If Me.SelectedRectangle <> Rectangle.Empty Then
                e.Graphics.FillRectangle(Brushes.Cyan, Me.SelectedRectangle)
                e.Graphics.DrawRectangle(New Pen(Color.Black, 3), Me.SelectedRectangle)
            End If
 
        End Using
 
        MyBase.OnPaint(e)
    End Sub
 
    Private Sub CaptureThisArea(ByVal area As Rectangle)
        Try
            Dim bmp As New Bitmap(area.Width, area.Height, Imaging.PixelFormat.Format24bppRgb)
            Dim filenamerandom As Integer
            Dim random As New Random()
            filenamerandom = random.Next(100000000, 999999999)
            Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
            Using g As Graphics = Graphics.FromImage(bmp)
                Dim srcDC As IntPtr = GetDC(IntPtr.Zero)
                Dim destDC As IntPtr = g.GetHdc()
 
                BitBlt(destDC, 0, 0, area.Width, area.Height, srcDC, area.X, area.Y, 13369376) 'SRCCOPY = 13369376
 
                g.ReleaseHdc(destDC)
                ReleaseDC(IntPtr.Zero, srcDC)
            End Using
Merci