Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Showing a window right under the cursor

1 view
Skip to first unread message

Jonathan Sion

unread,
Dec 16, 2007, 11:21:33 AM12/16/07
to
Hi,
I dont think this one is too dificult: i wish to show a windows form ,
its upper left corner would be right where the mouse is right now,
(sort of like a popup menu)

what i do is is something like:

dim loc as Point = Cursor.Position
myForm..SetDesktopLocation(loc .X, loc .Y)
myForm.Show

however, the window is never appearing where i want it to... what's
wrong?

thanks

ShaneO

unread,
Dec 16, 2007, 7:27:19 PM12/16/07
to

Your myForm.Show is shown relative to the Desktop, whereas your
Cursor.Position is relative to the current Form.

Add the X,Y position of the current Form to the
myForm.SetDesktopLocation(loc.X, loc.Y) and you'll find your myForm.Show
will open in the correct position.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Jonathan Sion

unread,
Dec 17, 2007, 9:41:20 AM12/17/07
to
Thanks Shane
while I believe you are right, this still doesnt work.. and I am not
sure what's the reason. somehow the form doesnt take the coordinates i
give it. the form has a method, something like this:

Public Sub ShowThisForm(ByVal atPos As Point)
Me.SetDesktopLocation(atPos.X, atPos.Y)
Me.TopLevel = True
Me.Show()
End Sub

and it keeps showing all over the place... each time at a different
position. would you know why?

thanks again

Nyx37

unread,
Dec 17, 2007, 10:36:00 PM12/17/07
to
how are you instangating the form, and are you seting the the StartPosition
property?

Nyx37

unread,
Dec 17, 2007, 11:12:00 PM12/17/07
to
To further expand on my reply.
I would instagate the form and set the properties before calling the show
method.
an example: (pls excuse any mistakes as I am not where I can access VS).

Dim frm as FormToShow = New FormToShow

frm.StartPosition = FormStartPosition.Manual
frm.TopLevel = True
frm.Location = New Point(Cursor.Position.X + ActiveForm.Location.X, _
Cursor.Position.Y + ActiveForm.Location.Y)
frm.Show()

0 new messages