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
|
Imports System.Runtime.InteropServices
Imports System.Drawing.Imaging
Public Class Form1
Const CURSOR_SHOWING As Int32 = &H1
Dim curseurs() As Cursor = {Cursors.Arrow, Cursors.Cross, _
Cursors.Hand, Cursors.Help, _
Cursors.HSplit, Cursors.IBeam, Cursors.No, _
Cursors.NoMove2D, Cursors.NoMoveHoriz, Cursors.NoMoveVert, _
Cursors.PanEast, Cursors.PanNE, Cursors.PanNorth, _
Cursors.PanNW, Cursors.PanSE, Cursors.PanSouth, _
Cursors.PanSW, Cursors.PanWest, Cursors.SizeAll, _
Cursors.SizeNESW, Cursors.SizeNS, Cursors.SizeNWSE, _
Cursors.SizeWE, Cursors.UpArrow, Cursors.VSplit, Cursors.WaitCursor}
Dim curseurIndex As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' ici tu peux tester en changeant du curseur
curseurIndex += 1
If curseurIndex > 25 Then
curseurIndex = 0
End If
Me.Cursor = curseurs(curseurIndex)
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Space Then
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
PictureBox1.Image = CaptureScreen(True)
e.SuppressKeyPress = True
End If
End Sub
Public Shared Function CaptureScreen(ByVal CaptureMouse As Boolean) As Bitmap
Dim result As Bitmap = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format24bppRgb)
Try
Using g As Graphics = Graphics.FromImage(result)
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
If (CaptureMouse) Then
Dim pci As CURSORINFO
pci.cbSize = Marshal.SizeOf(GetType(CURSORINFO))
If (GetCursorInfo(pci)) Then
If (pci.flags = CURSOR_SHOWING) Then
DrawIcon(g.GetHdc(), pci.ptScreenPos.x, pci.ptScreenPos.y, pci.hCursor)
g.ReleaseHdc()
End If
End If
End If
End Using
Catch ex As Exception
result = Nothing
End Try
Return result
End Function
<DllImport("user32.dll")>
Shared Function GetCursorInfo(ByRef pci As CURSORINFO) As Boolean
End Function
<DllImport("user32.dll")>
Shared Function DrawIcon(ByVal hDC As IntPtr, ByVal X As Int32, ByVal Y As Int32, ByVal hIcon As IntPtr) As Boolean
End Function
<StructLayout(LayoutKind.Sequential)>
Structure CURSORINFO
Public cbSize As Int32
Public flags As Int32
Public hCursor As IntPtr
Public ptScreenPos As POINTAPI
End Structure
<StructLayout(LayoutKind.Sequential)>
Structure POINTAPI
Public x As Int32
Public y As Int32
End Structure
End Class |
Partager