Drawing Lines and Rectangles

Started by Andy Flowers, September 09, 2009, 02:20:07 AM

Previous topic - Next topic

Andy Flowers

I am looking for a way to draw a rectangle around a group of controls (do not wish to use the frame control) and a line to seperate controls. Any suggestions or code to show me how to do this in FF.

Andy Flowers

TechSupport

Hi Andy,

You draw lines, rectangles, etc... in the WM_PAINT handler for the Form. Here is some example code to get you started.


Function FORM1_WM_PAINT ( _
                        hWndForm      As Dword _  ' handle of Form
                        ) As Long
                       
                       
   Local hDC    As Dword
   Local hPen   As Dword
   Local hBrush As Dword
   
   ' Get the DC for this form
   hDC = GetDC( hWndForm )
   
   ' Save the DC's contents so we can restore them later
   SaveDC hDC
   
   ' Create a pen to use with our rectangle. The width is 1 and
   ' uses a red color.
   hPen   = CreatePen( %PS_SOLID, 1, %Red )

   ' If we want our rectangle to have a solid background color
   ' then we create a solid brush, otherwise I just use a hollow brush.
   'hBrush = CreateSolidBrush( %Blue )
   hBrush = GetStockObject(%HOLLOW_BRUSH)
   
   ' Select the objects into the DC
   SelectObject hDC, hPen
   SelectObject hDC, hBrush
   
   ' Draw the rectangle. The rectangle uses the currently defined
   ' pen to draw the border and brush to fill the inside. We could
   ' use RoundRect api if we want a rectangle with rounded corners.
   Rectangle hDC, 20, 20, 200, 200
     
   ' To draw a line, simple use the MoveTo and LineTo api.
   MoveTo hDC, 20, 225
   LineTo hDC, 500, 225
   
   ' Restore the contents of our saved DC
   RestoreDC hDC, -1
   
   ' Delete the objects that we created
   DeleteObject hPen
   DeleteObject hBrush
   
   ' Release the DC.
   ReleaseDC hWndForm, hDC                     

End Function


Andy Flowers