Problem positioning a form

C

Colin McGuire

Hi, would someone be able to verify this crazy behaviour/

1. Launch VS.Net 2003, create a new project with a "Form1"
2. Add "Button1" to the form.
3. Paste in the code below.

When I move the cursor over the button & leave it there a while (for
the hover event to fire), the form displays. Note the position. I move
the cursor away from the button, then back onto it to fire the hover
event again, and for the second and all subsequent times, the form is
positioned in a different place to originally. So why it is not
displayed at 100,100 the first time, but for the second, third, fourth
etc?

Thank you (again)
Colin

Public Class Form1
Inherits System.Windows.Forms.Form

'Windows Form Designer generated code <start>
'
' <snip>
'
'Windows Form Designer generated code <end>


Dim frm As New Form

Private Sub hoverDisplayNewForm(ByVal sender As Object, _
ByVal e As System.EventArgs)
frm.Location = New Point(100, 100)
frm.Show()
End Sub


Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
AddHandler Button1.MouseHover, AddressOf hoverDisplayNewForm
frm.Size = New Size(50, 50)
End Sub

End Class
 
J

Jay B. Harlow [MVP - Outlook]

Colin,
Because the default for start position is
FormStartPosition.WindowsDefaultLocation which means that Windows itself
controls where the form will appear, if you want the form in a specific
location set the StartPostion to like FormStartPostion.Manual.

Hope this helps
Jay
 
C

Cor

Hi Colin,
Or in addition to Jay B.
Private Sub hoverDisplayNewForm(ByVal sender As Object, _
ByVal e As System.EventArgs)
frm.Location = New Point(100, 100)
frm.Show()
End Sub


Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

frm.Location = New Point(100, 100)
(Or get that position from the registry or a config file, and if it is from
the registry make a default or whatever, but test it that it exist the first
time)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top