Adblock breaks this site

Easy to to obtain the true X & Y position of your form?

Discussion in 'Programming General' started by Covey, Apr 30, 2011.

  1. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Easy to to obtain the true X & Y position of your form?

    Is there is easy way to obtain the TRUE X and Y position of your form relative to the screen?
    Code:
    me.bounds.left 'or .x
    Just if you you're forms X position including the border...i just need the clientsize's X. (inside the border).

    I have made a work around by a rather long winded math formula using clientsize.width and me.width etc

    But was just wondering if there was a simpler way?
     
  2. Flopper

    Flopper Member

    Joined:
    Feb 28, 2011
    Posts:
    42
    Referrals:
    0
    Sythe Gold:
    0
    Easy to to obtain the true X & Y position of your form?

    I'm unaware of the depths of your question, so I was rather hesitant in offering a simple solution, but I'll start out nonetheless:
    * Have you paid attention to PointToScreen? That'd go:

    Code:
    Dim screenCoordinates as Point = PointToScreen(FormName.Location)
    If this isn't what you were looking for; could you elaborate? :)
     
  3. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Easy to to obtain the true X & Y position of your form?

    nope that is just what i was after, thanks heaps :D
     
  4. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Easy to to obtain the true X & Y position of your form?

    My mistake, it still seems to be off by a few pixels.
    What i'm trying to do is get the x y co-ordinate of the ACTUAL form not the border of the form.
     
  5. Flopper

    Flopper Member

    Joined:
    Feb 28, 2011
    Posts:
    42
    Referrals:
    0
    Sythe Gold:
    0
    Easy to to obtain the true X & Y position of your form?

    How about overriding the OnPaint of the form and taking the ClipRectangle? I can't test it right on this PC and I don't know enough about it to tell you if it's the correct way. Try it out and see if it gives you the desired results, though.

    Make a global variable somewhere and override the OnPaint of the form:
    Code:
    Public Class Form1
        Public paintpoint As Point
    
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
    
            paintpoint = e.ClipRectangle.Location
        End Sub
    End Class
    .. and take the PointToScreen of the paintpoint variable.

    If that doesn't work, I can't help you, unless I look further into it ;)
     
  6. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Easy to to obtain the true X & Y position of your form?

    It's all good mate, i nutted it out :D
    i just put a control in the top corner of the form and got the pointtoscreen of that :D

    Thanks for the help ;)
     
< Just starting. Need advice! | * SwiftScreen BETA Released! * Screen Shot / Auto-Crop / Image Conversion >


 
 
Adblock breaks this site