Results 1 to 5 of 5

Thread: Draw a frame around a control

  1. #1
    Lively Member
    Join Date
    Dec 03
    Posts
    124

    Draw a frame around a control

    Hi I am using a Data grid on my form and in order for the appearance to 'Fit In' with the style of my form - I need to draw a '3D Light' type frame around it - (I know I could nest it in another control - but I would like to keep the number of controls on the form to a minimum for speed)

    Does anybody know how I can do this?

  2. #2
    Frenzied Member
    Join Date
    Aug 00
    Posts
    1,539
    you can create ur own control 2 ways

    1. by subclassing the original
    2. by creating an activex that is a datagrid within a frame


    i personally would go with just putting the datagrid in a frame without any subclassing or new activex, its faster than both of these methods..

  3. #3
    Lively Member
    Join Date
    Dec 03
    Posts
    124
    Yeah but can you use an API function to star trek the code to a level of effiency - I just wanna streamline

  4. #4
    Frenzied Member
    Join Date
    Aug 00
    Posts
    1,539
    if u use api's to do what i just said it will be slower than just putting the control in a frame, and a lot more code

  5. #5
    PowerPoster
    Join Date
    Oct 02
    Location
    British Columbia
    Posts
    9,758
    Adding a control won't affect the speed that much. Anyways, to draw fancy boxes use the DrawEdge API. It can draw several types of 3D boxes. Just remember that most API's which deal with coordinates are using pixels and not twips.

    Add this code to a Form and run the app. You should see two boxes, one that looks like a Frame Control and the other a depressed button.

    VB Code:
    1. Private Type Rect
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7.  
    8. Private Const BDR_RAISEDINNER = &H4
    9. Private Const BDR_RAISEDOUTER = &H1
    10. Private Const BDR_SUNKENINNER = &H8
    11. Private Const BDR_SUNKENOUTER = &H2
    12.  
    13. Private Const BF_BOTTOM = &H8
    14. Private Const BF_LEFT = &H1
    15. Private Const BF_RIGHT = &H4
    16. Private Const BF_TOP = &H2
    17. Private Const BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
    18.  
    19. Private Const EDGE_BUMP = (BDR_RAISEDOUTER Or BDR_SUNKENINNER)
    20. Private Const EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
    21. Private Const EDGE_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
    22. Private Const EDGE_SUNKEN = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)
    23.  
    24. Private Declare Function DrawEdge Lib "user32" (ByVal hDC As Long, qrc As Rect, ByVal edge As Long, ByVal grfFlags As Long) As Long
    25.  
    26. Private Sub Form_Paint()
    27.     DrawBox
    28. End Sub
    29.  
    30. Private Sub DrawBox()
    31.     Dim udtRect As Rect
    32.     Dim lngStatus As Long
    33.    
    34.     udtRect.Left = 10
    35.     udtRect.Bottom = 100
    36.     udtRect.Top = 10
    37.     udtRect.Right = 100
    38.    
    39.     lngStatus = DrawEdge(Me.hDC, udtRect, EDGE_ETCHED, BF_RECT)
    40.  
    41.     udtRect.Left = 120
    42.     udtRect.Bottom = 100
    43.     udtRect.Top = 10
    44.     udtRect.Right = 210
    45.    
    46.     lngStatus = DrawEdge(Me.hDC, udtRect, EDGE_SUNKEN, BF_RECT)
    47.  
    48. End Sub
    Last edited by brucevde; Dec 24th, 2003 at 11:26 AM.

Posting Permissions

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