簡體   English   中英

在GiveFeedback-Event中獲取當前的鼠標位置

[英]Get Current Mouse-Position in GiveFeedback-Event

我必須在執行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

結束子

怎么做對?

托爾斯滕的許多感謝和問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM