By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,682 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,682 IT Pros & Developers. It's quick & easy.

Problem positioning a form

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
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

Nov 20 '05 #2

P: n/a
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)
AddHandler Button1.MouseHover, AddressOf hoverDisplayNewForm
frm.Size = New Size(50, 50)
End Sub

End Class

Nov 20 '05 #3

P: n/a
Jay/Cor, thank you. Yes - this makes sense.
Colin
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.