Results 1 to 11 of 11

Thread: Polygon API coordinates

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Polygon API coordinates

    I have a picture box set to a scalewidth of 1 unit and a scaleheight of 1 unit, with scaleleft=0 and scaletop=1.
    I now wish to draw a polygon on the picturebox, but the Polygon API only works in pixel format - and I presume y then increases from the top to bottom.
    How can I convert my picturebox coordinates to pixel coordinates?

    Thanks
    PK

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,470

    Re: Polygon API coordinates

    Hello.
    Look at ScaleX and ScaleY.

    Code:
    'For horizontal coordinates:
    ValueInPixels = Picture1.ScaleX(Value, vbUser, vbPixels)
    Value = Picture1.ScaleX(ValueInPixels, vbPixels, vbUser)
    
    'For vertical coordinates:
    ValueInPixels = Picture1.ScaleY(Value, vbUser, vbPixels)
    Value = Picture1.ScaleY(ValueInPixels, vbPixels, vbUser)

  3. #3

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Re: Polygon API coordinates

    Eduardo,

    It gives me an invalid procedure call. I think the error has to do with the variable type. My new coordinates are of type POINTAPI which are long and my vbUser coordinates X11 and Y11 are of type single.

    I used it thus:

    Code:
    TMP(1).X = picZones.ScaleX(X11, vbUser, vbPixels): TMP(1).Y = picZones.ScaleY(Y11, vbUser, vbPixels)

    PK
    Last edited by Peekay; Feb 23rd, 2020 at 12:22 PM.

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,470

    Re: Polygon API coordinates

    Quote Originally Posted by Peekay View Post
    Eduardo,

    It gives me an invalid procedure call. I think the error has to do with the variable type. My new coordinates are of type POINTAPI which are long and my vbUser coordinates X11 and Y11 are of type single.

    I used it thus:

    Code:
    TMP(1).X = picZones.ScaleX(X11, vbUser, vbPixels): TMP(1).Y = picZones.ScaleY(Y11, vbUser, vbPixels)

    PK
    In what line you get the error?

    Try:

    Code:
    TMP(1).X = picZones.ScaleX(X11, vbUser, vbPixels): TMP(1).Y = picZones.ScaleY(picZones.ScaleHeight - Y11, vbUser, vbPixels)
    I think the error has to do with the variable type. My new coordinates are of type POINTAPI which are long and my vbUser coordinates X11 and Y11 are of type single
    I think it is probably something else.

  5. #5

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Re: Polygon API coordinates

    In what line you get the error?
    I get it in the .X first part.

  6. #6
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,470

    Re: Polygon API coordinates

    Please post a sample project to see the problem.

  7. #7
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,470

    Re: Polygon API coordinates

    Quote Originally Posted by Peekay View Post
    I have a picture box set to a scalewidth of 1 unit and a scaleheight of 1 unit, with scaleleft=0 and scaletop=1.
    I now wish to draw a polygon on the picturebox
    This picturebox is picZones?

    The ScaleX and ScaleY must be performed with the same PictureBox where you've set the custom scale.

  8. #8

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Re: Polygon API coordinates

    Thanks Eduardo,

    It works perfectly now. I put the scalemode to vbPixels before I did the scaleX - ignorance.

    PK

  9. #9

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Re: Polygon API coordinates

    I am at it again, and every time it is a battle to get it right.

    This is my latest routine for drawing a polygon on a PictureBox:

    Code:
    Friend Sub DrawPolygonFromUserMode(pic As Object, Points As Integer, Point() As Points2D, ForeColour As Long, FillColour As Long, FillStyle As Integer, LineWidth As Integer, Convert As Boolean)
    Dim Xscale As Single, Yscale As Single, i As Integer, TMP(1 To 10) As POINTAPI, MyDrawStyle As Integer, MyWidth As Single, MyHeight As Single, MyLeft As Single, MyTop As Single
    
    MyDrawStyle = pic.DrawStyle
    MyWidth = pic.ScaleWidth
    MyHeight = pic.ScaleHeight
    MyLeft = pic.ScaleLeft
    MyTop = pic.ScaleTop
    
    
    
    pic.FillStyle = FillStyle
    pic.DrawStyle = 0
    pic.FillColor = FillColour
    pic.ForeColor = ForeColour
    pic.DrawWidth = LineWidth
              
    For i = 1 To Points
        Tmp(i).X = pic.ScaleX(Point(i).X - pic.ScaleLeft, pic.ScaleMode, vbPixels)
        Tmp(i).Y = pic.ScaleY(Point(i).Y - pic.ScaleTop, pic.ScaleMode, vbPixels)
     Next i
    
    pic.ScaleMode = vbPixels
     
     
     
    Polygon pic.hDC, Tmp(1), Points            'draw the polygon
    
    pic.ScaleWidth = MyWidth
    pic.ScaleHeight = MyHeight
    pic.ScaleLeft = MyLeft
    pic.ScaleTop = MyTop
    pic.DrawStyle = MyDrawStyle
    
    
    
    End Sub
    It does not give an error but also do not draw the polygon (visibly)

    Thanks
    PK

  10. #10

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    673

    Re: Polygon API coordinates

    A funny thing happened on my way to the forum.

    I have checked everything and the coordinates are right, but ...

    When I go into debuggng mode just after calling the Polygon API, which did not display the polygon, I drew a square on the picture with the line box control, and when executing it with an immediate mode command of the filled square, it draws the square and simultaneously it also draws the polygon that was called in the previous command.

    When I execute a picture.refresh during runtime just after calling the polygon API , it then does draw the polygon. Why is this?

    Mystery!
    PK

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,537

    Re: Polygon API coordinates

    I assume you have AutoRedraw set to True.
    When you draw the polygon it is drawn with the API so Visual Basic doesn't know that you've drawn to the DC, so it won't refresh the screen automatically.
    When you draw the square using VB, then it knows it needs to refresh the screen, so you see VB's drawing and the API drawing.

    The rule is, if you have AutoRedraw set to True and you draw using the API calls, rather than drawing with VB, you need to do a refresh after you finish drawing so that the screen is updated with the drawing done behind "VB's back".
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width