Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.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
vb.net:使用像素化放大鼠标指针_Vb.net - Fatal编程技术网

vb.net:使用像素化放大鼠标指针

vb.net:使用像素化放大鼠标指针,vb.net,Vb.net,我正在用VB制作一个颜色选择器,我试图在一个picturebox中显示鼠标指针处的像素。它工作,但只有一次,只要我打开程序。我希望它能够启动和停止一个按钮和键盘上的一个键,并为它更新时,鼠标移动(最好每5毫秒)。我附上了我的代码和一些我的意思截图 我尝试过使用不同的循环,在计时器下运行,并用键盘上的enter键激活它 Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEven

我正在用VB制作一个颜色选择器,我试图在一个picturebox中显示鼠标指针处的像素。它工作,但只有一次,只要我打开程序。我希望它能够启动和停止一个按钮和键盘上的一个键,并为它更新时,鼠标移动(最好每5毫秒)。我附上了我的代码和一些我的意思截图

我尝试过使用不同的循环,在计时器下运行,并用键盘上的enter键激活它

Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

    Dim bmp As New Bitmap(10, 10)

    Using g As Graphics = Graphics.FromImage(bmp)

        Dim p As Point = MousePosition
        p.Offset(-2, 2)
        g.CopyFromScreen(p, New Point(0, 0), bmp.Size)

    End Using

    Dim w As Integer = PictureBox1.Width
    Dim h As Integer = PictureBox1.Height
    e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
    e.Graphics.DrawImage(bmp, 0, 0, w, h)

    Dim r As Rectangle
    r.X = w \ 2 - w \ 10
    r.Y = h \ 2 - h \ 10
    r.Width = w \ 5
    r.Height = h \ 5
    e.Graphics.DrawRectangle(Pens.LightGray, r)

End Sub
我尝试将所有这些代码放入一个重复循环(和一个计时器),但程序进入中断模式


(图像显示了当我将鼠标悬停在某个区域上时发生的情况,但当我移动鼠标光标时,picturebox不会更新)

因为您已分配PictureBox1\u paint事件,并且您说您有计时器,所以请尝试为计时器添加以下代码:

'this will automatically call your PictureBox1_Paint
'Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'    Dim bmp As New Bitmap(10, 10)
'    PictureBox1.Image = bmp
'End Sub

'this more better
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    PictureBox1.Refresh()
End Sub