5 Replies - 1880 Views - Last Post: 09 April 2013 - 09:15 AM Rate Topic: -----

#1 dasiyflowergirl17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 13

How can I make a screenshot selection region with crosshair?

Posted 08 April 2013 - 11:51 AM

Hello friends,

I have been making a screenshot program (in VB.NET) with shortcuts and helpful tools to use with facebook, etc.

I have have managed to make everything apart from the custom selection tools with the crosshair which gyazo uses.

I understand you have declare function to change system cursor (outside the form) such as.


Friend Declare Function SetSystemCursor Lib "User32" (ByVal hcur As Int64, ByVal id As Int64) As Int64




I can't find anywhere with a good explanation.

I have seen people say use a borderless form and use that as the selection region. But this is really unprofessional.

I would really aprieate it if someone could guide me in the right direction.

Is This A Good Question/Topic? 0
  • +

Replies To: How can I make a screenshot selection region with crosshair?

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How can I make a screenshot selection region with crosshair?

Posted 08 April 2013 - 06:01 PM

Don't think this is exactly what you're looking for but ricardosms has a tutorial that might lead you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#3 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 251
  • View blog
  • Posts: 810
  • Joined: 01-February 13

Re: How can I make a screenshot selection region with crosshair?

Posted 08 April 2013 - 11:12 PM

Hi,
Here is a simple example of using the (SetSystemCursor) API. When the button is pressed once it sets the system default cursor to the Cross cursor and when it is pressed again it sets the System default cursor back to the default cursor. However, it only shows the cross cursor when the mouse is over a window or control that uses the default cursor. If you put the mouse over a link or edit window then the systems Hand or Ibeam cursor will still be shown. For this example use a new form with 1 new button and paste this code in it.
Imports System.Runtime.InteropServices

Public Class Form1

    Const IDC_ARROW As Integer = 32512
    Const IDC_CROSS As Integer = 32515

    <DllImport("user32.dll")> Private Shared Function SetSystemCursor(ByVal hCursor As IntPtr, ByVal id As Integer) As Boolean
    End Function

    <DllImport("user32.dll")> Private Shared Function LoadCursor(ByVal hInstance As IntPtr, ByVal id As Integer) As IntPtr
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Cross As IntPtr = LoadCursor(IntPtr.Zero, IDC_CROSS)
        SetSystemCursor(Cross, IDC_ARROW)
    End Sub
End Class

If you have a special Cross cursor you want to load then here is a link to a project example at Code Project that shows how to load a custom cursor with the (LoadCursorFromFile) API.

As far as selecting an area of the screen, that is something you will have to write code to do using some API functions with your managed code. Even though you think a transparent form is unprofessional i can tell you from experience that it is going to be a lot less of a headache. If you want to try the API functions then here is a link to pinvoke where you can find most of them that are used with VB.NET. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: How can I make a screenshot selection region with crosshair?

Posted 08 April 2013 - 11:55 PM

dasiyflowergirl17,
I have a suggestion.
If you decide that changing the System cursor to a crosshair, and having it change depending on what the cursor is over, is not acceptable, perhaps there's a way to do the job more easily.

You could grab the whole screen, either right away or with a timer, or as a result of your own form becoming non-visible. You could then display the image as a full screen, in a borderless form, hiding the real scren. The user would then select the portion to be grabbed, and you can crop the image accordingly.

Just a thought.
Was This Post Helpful? 0
  • +
  • -

#5 dasiyflowergirl17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 13

Re: How can I make a screenshot selection region with crosshair?

Posted 09 April 2013 - 09:01 AM

View PostIronRazer, on 08 April 2013 - 11:12 PM, said:

Hi,
Here is a simple example of using the (SetSystemCursor) API. When the button is pressed once it sets the system default cursor to the Cross cursor and when it is pressed again it sets the System default cursor back to the default cursor. However, it only shows the cross cursor when the mouse is over a window or control that uses the default cursor. If you put the mouse over a link or edit window then the systems Hand or Ibeam cursor will still be shown. For this example use a new form with 1 new button and paste this code in it.
Imports System.Runtime.InteropServices

Public Class Form1

    Const IDC_ARROW As Integer = 32512
    Const IDC_CROSS As Integer = 32515

    <DllImport("user32.dll")> Private Shared Function SetSystemCursor(ByVal hCursor As IntPtr, ByVal id As Integer) As Boolean
    End Function

    <DllImport("user32.dll")> Private Shared Function LoadCursor(ByVal hInstance As IntPtr, ByVal id As Integer) As IntPtr
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Cross As IntPtr = LoadCursor(IntPtr.Zero, IDC_CROSS)
        SetSystemCursor(Cross, IDC_ARROW)
    End Sub
End Class

If you have a special Cross cursor you want to load then here is a link to a project example at Code Project that shows how to load a custom cursor with the (LoadCursorFromFile) API.

As far as selecting an area of the screen, that is something you will have to write code to do using some API functions with your managed code. Even though you think a transparent form is unprofessional i can tell you from experience that it is going to be a lot less of a headache. If you want to try the API functions then here is a link to pinvoke where you can find most of them that are used with VB.NET. :bigsmile:/>

Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 251
  • View blog
  • Posts: 810
  • Joined: 01-February 13

Re: How can I make a screenshot selection region with crosshair?

Posted 09 April 2013 - 09:15 AM

Hi,
Here is a quick example i made that uses a transparent form to make a selection on the screen with the mouse. Create a new Windows Form project and add 1 label, 1 button, and 1 timer. Then paste this code in.
Public Class Form1
    Dim sFrm As Form
    Dim sPoint As Point
    Dim selsize As Size
    Dim selstrt As Boolean = False
    Dim selmade As Boolean = False
    Dim mDown As Boolean = False

    Private Sub Button_StartMouseSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_StartMouseSelect.Click
        If selmade = True Then
            selmade = False
            sFrm.Close()
        End If
        Button_StartMouseSelect.Enabled = False
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If MouseButtons = Windows.Forms.MouseButtons.Left Then
            If mDown = False Then
                sPoint = New Point(MousePosition.X, MousePosition.Y)
                mDown = True
            Else
                selsize = New Size(Math.Abs(MousePosition.X - sPoint.X), Math.Abs(MousePosition.Y - sPoint.Y))
                Dim x As Integer = sPoint.X
                If sPoint.X > MousePosition.X Then x = MousePosition.X
                Dim y As Integer = sPoint.Y
                If sPoint.Y > MousePosition.Y Then y = MousePosition.Y
                If selsize.Width > 0 And selsize.Height > 0 And selstrt = False Then
                    selstrt = True
                    sFrm = New Form2
                    sFrm.Show()
                ElseIf selstrt = True Then
                    sFrm.Size = selsize
                    sFrm.Location = New Point(x, y)
                End If
            End If
        End If
        If MouseButtons = Windows.Forms.MouseButtons.None And selsize.Width > 0 And selsize.Height > 0 Then
            Timer1.Stop()
            selmade = True
            mDown = False
            selstrt = False
            selsize = New Size(0, 0)
            Button_StartMouseSelect.Enabled = True
            Dim sSize As Size = sFrm.ClientSize
            Dim sLoc As Point = sFrm.Location
            Label1.Text = "X=" & sLoc.X.ToString & ", Y=" & sLoc.Y.ToString & ", Width=" & sSize.Width.ToString & ", Height=" & sSize.Height.ToString
        End If
    End Sub
End Class

Now add a 2nd form to the project and paste this code in.
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Size = New Size(0, 0)
        Me.Location = New Point(MousePosition.X, MousePosition.Y)
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.BackColor = Color.Blue
        Me.TransparencyKey = Color.Blue
        Me.TopMost = True
    End Sub

    Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.DrawRectangle(New Pen(Color.Red, 2), Me.ClientRectangle)
    End Sub
End Class

You can press the button on form1 and then press the left mouse button down and drag the mouse to select the area. It makes a red box to show the area as you are dragging the mouse. When you release the button it shows the X, Y, Width, and Height of the selected area in the label. :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1