Sub ExactSize
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod("getResources")
r.Target = r.RunMethod("getDisplayMetrics")
xdpi = r.GetField("xdpi")
ydpi = r.GetField("ydpi")
End Sub
Private Sub DrawRuler
Private i, x1, x2, x3, x4, y1, y2, y3, y4 As Int
Private ScreenWidthmm, ScreenHeightmm As Int
Private xmm, ymm As Double
ExactSize
ScreenWidthmm = 100%x / xdpi * 25.4 'screen width in mm
ScreenHeightmm = 100%y / ydpi * 25.4 'screen height is mm
xmm = xdpi / 25.4 'number of X pixels per mm
ymm = ydpi / 25.4 'number of Y pixels per mm
y1 = 0dip
y2 = y1 + 12dip
y3 = y1 + 20dip
y4 = y1 + 30dip
For i = 0 To ScreenWidthmm
x1 = i * xmm
If i Mod 10 = 0 Then
cvsRuler.DrawLine(x1, y1, x1, y4, Colors.Black, 1dip)
Else If i Mod 5 = 0 Then
cvsRuler.DrawLine(x1, y1, x1, y3, Colors.Black, 1dip)
Else
cvsRuler.DrawLine(x1, y1, x1, y2, Colors.Black, 1dip)
End If
Next
x1 = 0dip
x2 = x1 + 12dip
x3 = x1 + 20dip
x4 = x1 + 30dip
For i = 0 To ScreenHeightmm
y1 = 100%y - i * ymm
If i Mod 10 = 0 Then
cvsRuler.DrawLine(x1, y1, x4, y1, Colors.Black, 1dip)
Else If i Mod 5 = 0 Then
cvsRuler.DrawLine(x1, y1, x3, y1, Colors.Black, 1dip)
Else
cvsRuler.DrawLine(x1, y1, x2, y1, Colors.Black, 1dip)
End If
Next
cvsRuler.Invalidate
End Sub