Problem to locate form

  • Thread starter Thread starter Jarek Mielcarek
  • Start date Start date
J

Jarek Mielcarek

hi,
I've problem to locate form on screen.
I'd like to show modal form near a textbox after user click on it.
here is the code:
Private Sub myTextBox_MouseDown(ByVal sender As Object, ByVal e As (...)
Dim r As New Rectangle(TextBox.Width, 1, 16, 18)
If r.Contains(New Point(e.X, e.Y)) Then
With popUp
.DesktopLocation = PointToScreen(New Point(r.Right - popUp.Size.Width,
r.Bottom + 2))
.Show()
End With
End If
End Sub

form popUp is hidden at start. after user click on textbox the popUp should
appear bottom of textbox.
and it does, but the first time popUp appear somewhere on the screen.
next I click on the textbox everything works fine.
the question is why it doesn't work first time?!

jaro
 
Hi Jarek.

Some questions:
How are you creating popUp?
What do you mean by 'hidden'?
- New only
- New, loaded but never visible
- New, Loaded, shown and hidden.
- something else

One possible workaround.
Set the Location
Call Show
Set the Location again.

Doing this, the first showing of the form may cause a 'jump' but it will
end up in the right place.

Regards,
Fergus
 
Fergus said:
Hi Jarek.

Some questions:
How are you creating popUp?
What do you mean by 'hidden'?
- New only
- New, loaded but never visible
- New, Loaded, shown and hidden.
- something else

One possible workaround.
Set the Location
Call Show
Set the Location again.

Doing this, the first showing of the form may cause a 'jump' but
it will end up in the right place.

Regards,
Fergus

hi Fergus,
thx for reply.
popUp form is created from code and is "- New, loaded but never visible".
I knew that setting location twice form is jumping on the screen.
How to display this form just in place I want without 'jump effect'?

jarek
 
Hi Jarek,

I believe the problem is caused by the
New, loaded but never visible

What I'm thinking is happening is that you have Form.StartPosition set to
WindowsDefaultLocation. So Windows gets to decide where your Form appears.
This will happen the first time that it is shown. Thereafter it'll be fine -
wherever you last placed it.

Try setting it to Manual and see if that improves things. If not, set it's
initial; coords so that it's off the screen (or just showing a single pixel or
somthing).

If it's then still jumping, you'll have to post some code for - popUp New,
Init and Load and where it is declared and created in the main form.

Regards,
Fergus
 
Back
Top