Drawing borders on different controls with GDIPLUS

Drawing borders on different controls with GDIPLUS

Postby ukoenig » Sat Mar 23, 2019 7:17 pm

Here are the final results testing borders / brushes on different controls
like xBrowse, Say, Get, Button, Radio, Dtpicker ... :
The border size / position is calculated from < nLeft, nTop, nWidth, nHeight >
but You can draw on screen on any position with any size You like.

The cellborder on xBrowse field < age > is a different solution :!:
added to test cellcolors on xBrowse-brushes

Image

The function-call

easy to use just copy this part to the bottom of the dialog
rename the object-names and delete or duplicate the objects.
Next Include the function < DRAWBORDER >.

For a calculated Radio-border instead of using fixed values You can replace :
DRAWBORDER( hDC, 528, 32, 130, 330, 30, 5, 16755801, .T. ), ; // Radio-border
with ( calculated ) :

DRAWBORDER( hDC, oRadio1:aItems[1]:nLeft -10, oRadio1:aItems[1]:nTop -10, ;
oRadio1:aItems[1]:nWidth +15, oRadio1:aItems[6]:nBottom - 20, 20, 5, 16755801, .T. ), ; // blue
or
DRAWLIGHT( hDC, oRadio1:aItems[1]:nLeft -10, oRadio1:aItems[1]:nTop -10, ;
oRadio1:aItems[1]:nWidth +15, oRadio1:aItems[6]:nBottom - 20, 20, 5, 255, .T. ), ; // red

oRadio1:aItems[6] = last item to calculate the bottom

Code: Select all  Expand view  RUN

oDlg:bPainted := < |hDC|
( DRAWLIGHT( hDC, oBrw:nLeft -2, oBrw:nTop -2, ;
     oBrw:nWidth +4, oBrw:nHeight +4, 5, 5, 255, .T. ), ; // xBrowse-border
  DRAWBORDER( hDC, oGet[4]:nLeft -2, oGet[4]:nTop -2, ;
     oGet[4]:nWidth +4, oGet[4]:nHeight +4, 0, 5, 16755801, .T. ), ; // Dtpicker-border
  DRAWBORDER( hDC, 528, 32, 130, 330, 30, 5, 16755801, .T. ), ; // Radio-border
  DRAWBORDER( hDC, oSay[1]:nLeft -2 -5, oSay[1]:nTop -2, ;
     oSay[2]:nWidth +2, oSay[1]:nHeight + oSay[2]:nHeight +2, 10, 0, 16755801, .F. ), ; // Say-border
  DRAWBORDER( hDC, oSay[3]:nLeft -2 -5, oSay[3]:nTop -2, ;
     oSay[3]:nWidth +2, oSay[5]:nHeight, 10, 5, 15125916, .T. ), ; // Brush for 2 says
  DRAWBORDER( hDC, oGet[3]:nLeft -2, oGet[3]:nTop -2, ;
     oGet[3]:nWidth +4, oGet[3]:nHeight +4, 0, 5, 16755801, .T. ), ; // Get-border
  DRAWLIGHT( hDC, oBtn[17]:nLeft -2, oBtn[17]:nTop -2, ;  
     oBtn[17]:nWidth +4, oBtn[17]:nHeight +4, 5, 5, 255, .T. ) ) // Button-border
RETURN NIL
>
 


The function

Code: Select all  Expand view  RUN

FUNCTION DRAWBORDER ( hDC, nLeft, nTop, nWidth, nHeight, nRadius, nPen, nRGBColor, lBorder )
LOCAL oGraphics := Graphics():New( hDC )
LOCAL nRed := nRGBRed( nRGBColor )
LOCAL nGreen := nRGBGreen( nRGBColor )
LOCAL nBlue := nRGBBlue( nRGBColor )
LOCAL oPen, oBrush, oPath

// Pen-Object -> nTransparency, nRed, nGreen, nBlue, [nSize], [lRound], [lInset]
// DrawRect( oPen, oBrush, nLeft, nTop, nWidth, nHight )
// AddRectangle ( nLeft, nTop, nRight, nBottom )  
// AddRoundRect( x, y, nWidth, nHeight, nRadious )
// Brush-Object -> nTransparency, nRed, nGreen, nBlue
// FillPath( oBrush, oPath)

IF  lBorder = .T.
    IF nRadius > 0
        oPath := Path():new()
        oPen := Pen():New( 255, nRed, nGreen, nBlue, nPen , .T.)
        oPath:AddRoundRect( nLeft, nTop, nWidth, nHeight, nRadius )
        oGraphics:DrawPath( oPen, oPath )  
    ELSE
        oPen := Pen():New( 255, nRed, nGreen, nBlue, nPen )
        oGraphics:DrawRect( oPen,  ,nLeft, nTop, nWidth, nHeight )
    ENDIF
ELSE
    oBrush := Brush():NewSolidBrush( 255, nRed, nGreen, nBlue )
    IF nRadius > 0
        oPath := Path():new()
        oPath:AddRoundRect( nLeft, nTop, nWidth, nHeight, nRadius )
        oGraphics:FillPath( oBrush, oPath)
    ELSE
        oGraphics:DrawRect( , oBrush, nLeft, nTop, nWidth, nHeight )
    ENDIF
ENDIF
oGraphics:destroy()

RETURN NIL

// ------------------

FUNCTION DRAWLIGHT(hDC, nLeft, nTop, nWidth, nHeight, nRadius, nPen, nRGBColor, lBorder)
LOCAL oGraphics := Graphics():New( hDC )
LOCAL oPen
LOCAL n
LOCAL nRed := nRGBRed( nRGBColor )
LOCAL nGreen := nRGBGreen( nRGBColor )
LOCAL nBlue := nRGBBlue( nRGBColor )

oPen := Pen():New(  255 , 0, 0 , 0 , .T.)
oGraphics:DrawRoundRect( oPen, , nLeft, nTop, nWidth, nHeight )
   
oPen:SetColor( 255 , nRed, nGreen, nBlue )
 
oPen:Setsize(1)

FOR n = 1 to 10
    oPen:Setcolor( 255-n*25 , nRed, nGreen, nBlue )
    oGraphics:DrawRoundRect( oPen, , nLeft-n , nTop-n,  nWidth+n*2 , nHeight+ n*2  )
NEXT
oPen:Destroy()
   
oGraphics:Destroy()

RETURN NIL
 


regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests