Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbUser
Me.ScaleLeft = -100
Me.ScaleTop = 100
Me.ScaleWidth = 200
Me.ScaleHeight = -200
Me.PSet (0, 0), vbRed
Me.Circle (0, 0), 10, vbRed
End Sub
[blue]' Move graphics origin to position X,Y pixels
' On return X and Y contain previous graphics origin
Private Sub MoveGraphicsOrigin(Target As PictureBox, ByRef X As Long, ByRef Y As Long)
Dim PreviousOrigin As POINTAPI
Dim PreviousScaleMode As Long
PreviousScaleMode = Target.ScaleMode
Target.ScaleMode = vbPixels
SetViewportOrgEx Target.hdc, X, Y, PreviousOrigin ' Works in device units, i.e pixels
Target.ScaleMode = PreviousScaleMode
X = PreviousOrigin.X
Y = PreviousOrigin.Y
End Sub[/blue]
Option Explicit
Private Declare Function SetViewportOrgEx Lib "gdi32" (ByVal hdc As Long, ByVal nX As Long, ByVal nY As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
' Move graphics origin to position X,Y pixels
' On return X and Y contain previous graphics origin
Private Sub MoveGraphicsOrigin(Target As [b]Form[/b], ByRef X As Long, ByRef Y As Long)
Dim PreviousOrigin As POINTAPI
Dim PreviousScaleMode As Long
PreviousScaleMode = Target.ScaleMode
Target.ScaleMode = vbPixels
SetViewportOrgEx Target.hdc, X, Y, PreviousOrigin ' Works in device units, i.e pixels
Target.ScaleMode = PreviousScaleMode
X = PreviousOrigin.X
Y = PreviousOrigin.Y
End Sub
Private Sub Form_Load()
Show
MoveGraphicsOrigin Me, ScaleWidth / 2, ScaleHeight / 2
' the following two lines don't quite work...
PSet (0, 0), vbRed
Line (0, 0)-(100, 100), vbRed
End Sub
[blue]
Private Sub Form_Load()
[green]' Remember: MoveGraphicsOrigin requires X and Y passsed as pixel value
' so, if we are going to use ScaleWidth and Scaleheight we need to ensure
' ScaleMode is vbPixels[/green]
[b]ScaleMode = vbPixels[/b]
Show
[b]Refresh [green]' Give form chance to update itself *before* we muck about with it ...[/green][/b]
MoveGraphicsOrigin Me, ScaleWidth / 2, ScaleHeight / 2
[green]' the following two lines don't quite work...[/green]
PSet (0, 0), vbRed
Line (0, 0)-(100, 100), vbRed
End Sub[/blue]