.net 在这个屏幕放大镜上画一个漂亮的十字指示器?
我想画一个漂亮的“指示器”,比如一个十字架或其他东西,以准确地知道鼠标在屏幕放大镜中的位置,在鼠标或像素周围画一个十字指示器 毫无疑问,我的GDI+知识不好 这是放大镜窗口的外观: 我想画一个指示器,当前的鼠标指针,或者像这样的交叉指示器(但这太难看了,而且有像素精度,因为我用了MsPaint) 有人能帮我吗 这是我如何绘制图像的:.net 在这个屏幕放大镜上画一个漂亮的十字指示器?,.net,vb.net,drawing,gdi+,paint,.net,Vb.net,Drawing,Gdi+,Paint,我想画一个漂亮的“指示器”,比如一个十字架或其他东西,以准确地知道鼠标在屏幕放大镜中的位置,在鼠标或像素周围画一个十字指示器 毫无疑问,我的GDI+知识不好 这是放大镜窗口的外观: 我想画一个指示器,当前的鼠标指针,或者像这样的交叉指示器(但这太难看了,而且有像素精度,因为我用了MsPaint) 有人能帮我吗 这是我如何绘制图像的: ''' <summary> ''' Repaints the Magnifier. ''' </summary> Private Sub
''' <summary>
''' Repaints the Magnifier.
''' </summary>
Private Sub Repaint()
' Region Length.
Dim lengthX As Single = Me.Width * ZoomFactor
Dim lengthY As Single = (Me.Height - ZoomFactor_KryptonTrackBar.Bounds.Height) * ZoomFactor
' Center Image Around The Mouse.
Dim offsetX As Single = (Me.Width * ZoomFactor) \ 2
Dim offsetY As Single = (Me.Height * ZoomFactor) \ 2
' Actual Area To Blit To.
Dim blitAreaX As Integer = Me.Width
Dim blitAreaY As Integer = Me.Height - ZoomFactor_KryptonTrackBar.Bounds.Height
bmp = New Bitmap(CInt(blitAreaX), CInt(blitAreaY))
g1 = ZoomFactor_PictureBox.CreateGraphics
g2 = Graphics.FromImage(bmp)
' Set the image quality.
g1.SmoothingMode = SmoothingMode.None
g1.CompositingQuality = CompositingQuality.HighSpeed
g1.PixelOffsetMode = PixelOffsetMode.HighSpeed
g1.InterpolationMode = InterpolationMode.NearestNeighbor
g2.SmoothingMode = SmoothingMode.None
g2.CompositingQuality = CompositingQuality.HighSpeed
g2.PixelOffsetMode = PixelOffsetMode.HighSpeed
g2.InterpolationMode = InterpolationMode.NearestNeighbor
' Devicecontext (DC) of the Desktop and the Graphics object.
Dim hWndWindow As IntPtr = GetDesktopWindow()
Dim hdcWindow As IntPtr = GetDC(hWndWindow)
Dim hdcGraphics As IntPtr = g2.GetHdc()
' BitBlt the Screen (Captures Transparent Windows & Prevents Mirror Effect)
BitBlt(hdcGraphics.ToInt32, 0, 0, blitAreaX, blitAreaY,
hdcWindow.ToInt32, MousePosition.X - offsetX, MousePosition.Y - offsetY,
TernaryRasterOperations.SRCCOPY Or
TernaryRasterOperations.CAPTUREBLT Or
TernaryRasterOperations.NOMIRRORBITMAP)
' Free Memory
ReleaseDC(hWndWindow, hdcWindow)
g2.ReleaseHdc(hdcGraphics)
' Paint
g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel)
' Set Magnifier position.
' Do this after painting to reduce blinking effects.
SetMangifierPosition()
End Sub
更新2
已解决:
' Paint
g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel)
' Set the cursor Rectangle.
Dim CursorRect As New Rectangle With
{
.Size = New Size(0, 0),
.Location = New Point((ZoomFactor_PictureBox.Width \ 2) - Cursors.Cross.Size.Width \ 2,
(ZoomFactor_PictureBox.Height \ 2) - Cursors.Cross.Size.Height \ 2 - 10)
}
' Paint the mouse cursor
Cursors.Cross.Draw(g1, CursorRect)
您可以将十字线的png以透明背景存储,并将
DrawImage
放在现有的上方:
或手动绘制g1.绘制线
四次:
我已按照您的建议进行操作,但光标仍有问题,请查看我的更新
' Paint
g1.DrawImage(bmp, New Rectangle(0, 0, blitAreaX, blitAreaY), 0, 0, lengthX, lengthY, GraphicsUnit.Pixel)
' Set the cursor Rectangle.
Dim CursorRect As New Rectangle With
{
.Size = New Size(0, 0),
.Location = New Point((ZoomFactor_PictureBox.Width \ 2) - Cursors.Cross.Size.Width \ 2,
(ZoomFactor_PictureBox.Height \ 2) - Cursors.Cross.Size.Height \ 2 - 10)
}
' Paint the mouse cursor
Cursors.Cross.Draw(g1, CursorRect)