Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91

    Unanswered: How to draw line?

    Is there any way to draw line on Access Form using VB Code?

  2. #2
    Join Date
    Sep 2002
    Location
    Coventry, Warwickshire, UK
    Posts
    74
    The best way is to place the line on the form roughly where you want it and then alter the position and length using the following

    Me!Line1.Top = 24
    Me!line1.Left = 0
    Me!line1.Width = 19

    If you want a slanting line, you could also use

    Me!Line1.Height = 5

    for example.
    Roger Hampson
    XI - ecs (UK) Ltd

  3. #3
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91

    "ready to use" lines

    Hm... I think I have new idea...
    I use other form, and create Line0 to Line99, then copy all lines to the form that already have Label0 to Label99, I will get 100 "ready to use" lines and 100 "ready to use" labels...
    Later I just add on the dummy form... if I need more than 100 lines and labels... and the numbering will be consistent...

    Any better idea?

  4. #4
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    That's not the good way to do it, Acces form are limited, I would like to suggest you to use LineTo API, but the problem is that you need a Window Handle, and there is no controls on Access that have such a things, except maybe report .

    The following code would work perfectly in a Visual Basic form, you should consider using VB, you'll be able to draw those lines and to create label at runtime, but anyway, you could make it works with a blank report:

    Two parts, first add the declarations of API in a module, and then use them with code.

    Code:
    'Module declaration
    Public Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Public Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
    Public Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
    Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    
    
    'A form code, don't work properly, hwnd don't work with Access form
    Private Sub Commande2_Click()
        Dim papi As POINTAPI
    
      
        MoveToEx GetDC(Me.hwnd), 10, 10, papi
        LineTo GetDC(Me.hwnd), 100, 100
        
    End Sub
    Just my two cents

    JefB - hope it helps

  5. #5
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91

    Arrow

    Yes... I already try this method before using "ready to use" lines. GetDC is successful, but i can't see any changes made by LineTo. Previously I think the problem is on the pens and color, maybe this is really the access limitation...

  6. #6
    Join Date
    Aug 2002
    Location
    Québec, Canada
    Posts
    109
    Yes, as I said, Access Form hwnd do not give proper DC, you can't use these API in Access (or maybe with a valid hwnd), but you can use them on a Visual Basic form. Actually, the Line is draw, but on the selector window, and not the main window (just try it, give the show selector window property to true)

    JefB

  7. #7
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    91
    Just an idea to try. I will try this...
    "Use API FindWindowExA to get the Hwnd of Access Form..."

Posting Permissions

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