Results 1 to 3 of 3

Thread: [RESOLVED] Relative to container not screen

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    Resolved [RESOLVED] Relative to container not screen

    I have a panel that is called "Self" and I would like to make it follow the exact mouse movements.

    I have done this. However it is not centred with the mouse and is reliant upon where the form is located on the screen. I don't want this.

    VB Code:
    1. Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
    2.         X = Control.MousePosition.X
    3.         Y = Control.MousePosition.Y
    4.         Self.Location = New Point(X - 5, Y - 5)
    5.     End Sub

    How do I solve this problem. thanks.
    Last edited by emdiesse; Jun 24th, 2006 at 11:36 AM.
    Emdiesse

  2. #2
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: Relative to container not screen

    Control.MousePosition returns a point relative to the screen.

    To get the position of the mouse relative to your form, you need to convert this point by using the PointToClient method.

    VB Code:
    1. Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
    2.         Dim p As Point = PointToClient(Control.MousePosition)
    3.         X = p.X
    4.         Y = p.Y
    5.         Self.Location = New Point(X - 5, Y - 5)
    6. End Sub
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    125

    Re: Relative to container not screen

    Quote Originally Posted by Andy_P
    Control.MousePosition returns a point relative to the screen.

    To get the position of the mouse relative to your form, you need to convert this point by using the PointToClient method.

    VB Code:
    1. Private Sub Self_FollowMouse_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Self_FollowMouse.Tick
    2.         Dim p As Point = PointToClient(Control.MousePosition)
    3.         X = p.X
    4.         Y = p.Y
    5.         Self.Location = New Point(X - 5, Y - 5)
    6. End Sub
    Thank you.
    Emdiesse

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width