WarMacre
02-21-2009, 05:42 AM
Hey all. This my first query on here (and everywhere else) as I'm fed-up of hitting brick walls with VB .NET.
Here's the issue. I have a Shared function. From within this function I want to get the 'desktopLocation' of the primary form (Form1). I thought I had done it but I keep getting '0' returned regardless of where the form resides.
The Code in question:
(This is within Form1)
Private Sub TimeBarSlot_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblTimeBarSlot.MouseDown
timeBar.Width = MouseLoc.getMouseX - timeBarSlot.Left
End Sub
And this is the function (within a class) that it calls:
Friend Class MouseLoc
Public frm As Form1 = New Form1
Shared Function getMouseLoc() As Point
Dim _me As MouseLoc = New MouseLoc
getMouseLoc = _me.frm.MousePosition
getMouseLoc.X -= _me.frm.DesktopLocation.X
getMouseLoc.Y -= _me.frm.DesktopLocation.Y
Return getMouseLoc
End Function
Shared Function getMouseX() As Integer
Dim _me As MouseLoc = New MouseLoc
getMouseX = _me.frm.MousePosition.X
getMouseX -= _me.frm.DesktopLocation.X
Return getMouseX
End Function
Shared Function getMouseY() As Integer
Dim _me As MouseLoc = New MouseLoc
getMouseY = _me.frm.MousePosition.Y
getMouseY -= _me.frm.DesktopLocation.Y
Return getMouseY
End Function
End Class
Essentially, what this is doing is getting the mouse position when I click on a label called "timeBarSlot" and then subtracts the desktop location of the Form (or Application) to give a location co-ordinate that is relative to the Form dimensions and not the desktop dimensions.
Any ideas of where I am going completely and splutterly wayward?
Here's the issue. I have a Shared function. From within this function I want to get the 'desktopLocation' of the primary form (Form1). I thought I had done it but I keep getting '0' returned regardless of where the form resides.
The Code in question:
(This is within Form1)
Private Sub TimeBarSlot_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblTimeBarSlot.MouseDown
timeBar.Width = MouseLoc.getMouseX - timeBarSlot.Left
End Sub
And this is the function (within a class) that it calls:
Friend Class MouseLoc
Public frm As Form1 = New Form1
Shared Function getMouseLoc() As Point
Dim _me As MouseLoc = New MouseLoc
getMouseLoc = _me.frm.MousePosition
getMouseLoc.X -= _me.frm.DesktopLocation.X
getMouseLoc.Y -= _me.frm.DesktopLocation.Y
Return getMouseLoc
End Function
Shared Function getMouseX() As Integer
Dim _me As MouseLoc = New MouseLoc
getMouseX = _me.frm.MousePosition.X
getMouseX -= _me.frm.DesktopLocation.X
Return getMouseX
End Function
Shared Function getMouseY() As Integer
Dim _me As MouseLoc = New MouseLoc
getMouseY = _me.frm.MousePosition.Y
getMouseY -= _me.frm.DesktopLocation.Y
Return getMouseY
End Function
End Class
Essentially, what this is doing is getting the mouse position when I click on a label called "timeBarSlot" and then subtracts the desktop location of the Form (or Application) to give a location co-ordinate that is relative to the Form dimensions and not the desktop dimensions.
Any ideas of where I am going completely and splutterly wayward?