Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 222983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:10:42+00:00 2026-05-11T19:10:42+00:00

I have some Label controls sitting on Panel controls on a Form. I want

  • 0

I have some Label controls sitting on Panel controls on a Form. I want to get the labels’ positions relative to the form’s origin so that at run time I can hide the panel and the labels and draw some other text in their place directly onto the form.

Basically, I’m doing the following calculation: Get the absolute screen position of a label with Control.PointToScreen() and convert it back to a relative position with Control.PointToClient(), so either:

Dim newloc As Point = Me.PointToClient(ctl.PointToScreen(Point.Empty))

or

Dim newloc As Point = Me.PointToClient(ctl.Parent.PointToScreen(ctl.Location))

I have found that the two methods sometimes give me different results – putting my new point out of the visible area with negative values! – but haven’t been able to determine why. I would have thought they should be identical (and they are, most of the time).

Reading the docs didn’t help the first time around, but perhaps I skipped over something… Anyway, I’d be thankful for any help before I start tearing my hair out.

Or, on the other hand, is there a better way to do this?

Edit: Sample results

So, here’s a real example.

Label1 at {X=4,Y=6} on Panel1; Label2 at {X=163,Y=6} on the same parent, Panel1. Obviously I’m expecting different X-positions, but Y should be identical for both.

When I run the project both

ctl.PointToScreen(Point.Empty)

and

ctl.Parent.PointToScreen(ctl.Location)

give me the same screen location for Label1 at {X=959,Y=119} (the absolute values here can vary, of course, depending on the position of the form itself) and therefore the correct location relative to the form when Me.PointToClient is applied (at {X=5,Y=32}).

The very next lines do the same calculations for Label2 (remember, same Parent, same Y-value within the parent (6)), but the results are totally off: ctl.Parent.PointToScreen() gives me {X=1114,Y=63}. X is almost correct (959-4+163=1118), but Y is nowhere near the 119 I got for Label1. And then ctl.PointToScreen() gives me {X=166,Y=29} – translated back to Form-Coordinates (Me.PointToClient) {X=-784,Y=-2}.

These numbers are calculated and printed to the debug window directly after each other, without moving anything around… Madness.

OK, this is getting rather messy, but I still hope someone has a simple explanation. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:10:42+00:00Added an answer on May 11, 2026 at 7:10 pm

    OK, I found the solution.

    I happened to be calling Control.PointToScreen before the control was created: Control.IsHandleCreated = False.

    If I ensure that the control is created first (Control.CreateControl) both methods work equally well.

    The reason I had differing results on subsequent calls is that the first call to Control.PointToScreen also causes the control to be created (and therefore its parent and any other controls sited on the parent), meaning the second succeeds.

    Well, I’m sure glad to be done with this 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have some html like so: <div id=avatar_choices> <label for=id_choice_0> <input id=id_choice_0 type=radio
I have a program which has some Textareas / Labels these can be anywhere
In my fieldset I have labels next (side) to my textboxes, but for some
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have a parent form, with some child windows (not forms - just windows,
I would like to have some of the controls in an app - Button
I have a simple custom control that boils down to a label and a
I have a script that appends some rows to a table. One of the
I have some ASP.NET web services which all share a common helper class they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.