Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在屏幕上绘制点_.net_Graphics_Cursor - Fatal编程技术网

.net 在屏幕上绘制点

.net 在屏幕上绘制点,.net,graphics,cursor,.net,Graphics,Cursor,我需要读取的颜色和绘制到屏幕上的计算点 在旧版本的VB中,VB.NET与旧的Peek和Poke或PointSet和PointGet命令的等价物是什么 或者在另一种情况下,是否有一种方法可以将标签用作光标对象,以便在我移动picturebox时不会擦除它。我不能只制作一个光标图标,因为当我移动光标时标签中的文本必须改变。你不能将标签本身用作光标,但你可以将标签组件添加到表单中,并通过消息过滤器将其与光标同步移动,如下所示: Public Class Form1 Private Sub F

我需要读取的颜色和绘制到屏幕上的计算点

在旧版本的VB中,VB.NET与旧的Peek和Poke或PointSet和PointGet命令的等价物是什么


或者在另一种情况下,是否有一种方法可以将标签用作光标对象,以便在我移动picturebox时不会擦除它。我不能只制作一个光标图标,因为当我移动光标时标签中的文本必须改变。你不能将标签本身用作光标,但你可以将标签组件添加到表单中,并通过消息过滤器将其与光标同步移动,如下所示:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        Application.AddMessageFilter(New LabelMoveFilter)

    End Sub

    Private Class LabelMoveFilter
        Implements IMessageFilter

        Public Function PreFilterMessage(ByRef m As Message) As Boolean _
            Implements IMessageFilter.PreFilterMessage

            'If the message is &H200 (WM_MOUSEMOVE), reposition the label to
            'where the cursor has moved to

            If m.Msg = &H200 Then
                Form1.Label1.Location = Form1.PointToClient(Cursor.Position)
            End If

            'Return false so that the message is passed on to the form

            Return False

        End Function

    End Class

End Class
标签组件(在本例中为Label1)不会覆盖表单上的任何内容,它只会位于顶部。只需确保标签位于表单上所有其他组件的前面,这样它就不会滑到其他组件的后面。然后,您可以在适当的时候将标签的文本设置为所需的任何内容


编辑:要回答问题的另一部分

要获取和设置屏幕上的任意像素,可以使用Windows GDI GetPixel和SetPixel函数。按如下方式导入它们:

Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer) As Integer
然后将其称为:

color = ColorTranslator.FromOle(GetPixel(GetDC(0), x, y))

其中,x和y是屏幕(非窗体)坐标,颜色是要读取/设置的颜色。您可以使用cursor.Position.X和cursor.Position.Y获取光标的X/Y,如果这是您想要的X和Y。您可以使用PointToScreen和PointToClient方法分别从窗体到屏幕和从屏幕到窗体坐标进行转换


请注意,您设置的任何像素都将在重新绘制本身时被覆盖。请注意,这些组件也会在表单外部读/写,因此请小心。

您不能将标签本身用作光标,但可以向表单中添加标签组件,并通过消息过滤器将其与光标同步移动,如下所示:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        Application.AddMessageFilter(New LabelMoveFilter)

    End Sub

    Private Class LabelMoveFilter
        Implements IMessageFilter

        Public Function PreFilterMessage(ByRef m As Message) As Boolean _
            Implements IMessageFilter.PreFilterMessage

            'If the message is &H200 (WM_MOUSEMOVE), reposition the label to
            'where the cursor has moved to

            If m.Msg = &H200 Then
                Form1.Label1.Location = Form1.PointToClient(Cursor.Position)
            End If

            'Return false so that the message is passed on to the form

            Return False

        End Function

    End Class

End Class
标签组件(在本例中为Label1)不会覆盖表单上的任何内容,它只会位于顶部。只需确保标签位于表单上所有其他组件的前面,这样它就不会滑到其他组件的后面。然后,您可以在适当的时候将标签的文本设置为所需的任何内容


编辑:要回答问题的另一部分

要获取和设置屏幕上的任意像素,可以使用Windows GDI GetPixel和SetPixel函数。按如下方式导入它们:

Private Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer, ByVal crColor As Integer) As Integer
然后将其称为:

color = ColorTranslator.FromOle(GetPixel(GetDC(0), x, y))

其中,x和y是屏幕(非窗体)坐标,颜色是要读取/设置的颜色。您可以使用cursor.Position.X和cursor.Position.Y获取光标的X/Y,如果这是您想要的X和Y。您可以使用PointToScreen和PointToClient方法分别从窗体到屏幕和从屏幕到窗体坐标进行转换

请注意,您设置的任何像素都将在重新绘制本身时被覆盖。请注意,这些文件也会在表单之外读/写,所以要小心