在GiveFeedback-Event

时间:2018-10-12 15:35:34

标签: bitmap drag-and-drop cursor hotspot

在执行DragDrop完全控制期间,我必须绘制一些东西。 我从控件复制屏幕并进行绘制。 然后将图像用作光标。

问题在于,在光标中生成的图像需要Hospot,这取决于鼠标的位置。 但是,如何在GiveFeedback事件中获得正确的位置? 在我使用Control.MousePosition的版本中,但是图片来回摆动。这里是事件代码:

Private Sub Panel1_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles Panel1.GiveFeedback
Dim Pan As Panel = sender
Dim pMouseScreen = Control.MousePosition, pMouseClient = Pan.PointToClient(pMouseScreen)
Dim RPanelClient = Pan.ClientRectangle, RPanelScreen = Pan.RectangleToScreen(RPanelClient)
Using BMP As New Bitmap(RPanelClient.Size.Width, RPanelClient.Size.Height)
  Using Gr = System.Drawing.Graphics.FromImage(BMP)
    Gr.CopyFromScreen(RPanelScreen.Location, Point.Empty, BMP.Size)
    Gr.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
    Using P As New Pen(Color.Black, 5)
      Dim P1 = New Point(0, pMouseClient.Y), P2 = New Point(RPanelClient.Right - 1, pMouseClient.Y)
      Gr.DrawLine(P, P1, P2)
    End Using
    Dim Cur = Cursors.Default   ' 
    Dim Rcursor = New Rectangle(pMouseClient, Cur.Size)
    Cur.Draw(Gr, Rcursor)
  End Using
  e.UseDefaultCursors = False
  Cursor.Current = CreateCursorFromBMP(BMP, pMouseClient)
End Using

结束子

该怎么做对呢?

Torsten的许多感谢和问候

0 个答案:

没有答案