Link to home
Start Free TrialLog in
Avatar of capel
capel

asked on

Ruler on form

I would like to put scalable rulers at the top and left edge of a form. When the mouse moves an indication is given of position on the ruler. Is there code, control - preferably free that will do this?
Avatar of chabaud
chabaud

You could draw your rulers in pictureboxes.

Try create a form with one picturebox (use as top ruler):

Option Explicit

Private pos As Integer

Private Sub Form_Load()

    Dim i As Integer
   
    ScaleMode = vbPixels
    Picture1.Align = vbAlignTop
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True
    Picture1.width=350
    Picture1.DrawMode = vbCopyPen
   
    For i = 0 To 150
        If i Mod 10 Then
            Picture1.Line (3 * i, 0)-Step(0, 5)
        Else
            Picture1.CurrentX = 2 + 3 * i
            Picture1.CurrentY = 8
            Picture1.Print CStr(i \ 10)
            Picture1.Line (3 * i, 0)-Step(0, 10)
        End If
    Next
    Picture1.DrawMode = vbInvert
    Picture1.Line (pos, 0)-Step(1, 20), , BF
    Picture1.DrawMode = vbCopyPen
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture1.DrawMode = vbInvert
    Picture1.Line (pos, 0)-Step(1, 20), , BF
    pos = X
    Picture1.Line (pos, 0)-Step(1, 20), , BF
    Picture1.DrawMode = vbCopyPen
End Sub

ASKER CERTIFIED SOLUTION
Avatar of Johnn
Johnn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial