locked
Top,Left <> X,Y ? RRS feed

  • Question

  • A Maximized windows form contains a button (Button1) that when clicked upon executes following code:

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim Bfrm As New frmB
            With Bfrm
                .Top = 100
                .Left = 100
                .BackColor = Color.Coral
                .Text = "Bfrm Top,Left"
                .Show()
            End With
    
            Dim oP As New Point
            With oP
                .X = 100
                .Y = 100
            End With
    
            Dim Cfrm As New frmB
            With Cfrm
                .Location = oP
                .BackColor = Color.LightBlue
                .Text = "Cfrm - X,Y"
                .Show()
            End With
        End Sub
    
    

    frmB is another ordinary windows form that was added to the project.

    I have following questions:

    1. Why don't the forms show up at exactly the same place (and so entirely overlap)?

    2. If I execute the program more than once, the locations of Bfrm and Cfrm change (in fact they seem to alternate between two different locations)?

    3. Is there a way to convert the Point coordinates (X,Y) to (.Top,.Left) coordinates?

     

    Tuesday, October 4, 2011 4:49 PM

Answers

    1. Set the Form's Startposition property = Manual
    2. see 1.
    3. I don't understand .Location.y is equal to .Top

    Armin
    • Proposed as answer by Crazypennie Tuesday, October 4, 2011 6:31 PM
    • Marked as answer by Mike Feng Friday, October 21, 2011 5:33 AM
    Tuesday, October 4, 2011 4:54 PM

All replies

    1. Set the Form's Startposition property = Manual
    2. see 1.
    3. I don't understand .Location.y is equal to .Top

    Armin
    • Proposed as answer by Crazypennie Tuesday, October 4, 2011 6:31 PM
    • Marked as answer by Mike Feng Friday, October 21, 2011 5:33 AM
    Tuesday, October 4, 2011 4:54 PM
  • You're right, in the example I forgot to set the startposition to manual. 

    In the meantime I solved my problem in the real application, where X and Y have different values (In the above example both are equal to 100). 

    I stupid as it it is, I thought that X=Top and Y=Left, which I discovered to be false.

    X=Left, Y=Top

    Wednesday, October 5, 2011 4:45 PM