Menu

#59 flat border on label

v1.0_(example)
open
nobody
None
1
2023-11-02
2023-08-04
No

When I use WS_BORDER on label it is 3D. How to get flat border?

Discussion

  • Alexander S.Kresin

    I may suggest a workaround for this - using of ownerdrawn label
    ...
    @ 20,10 SAY cText SIZE 260, 22 STYLE SS_OWNERDRAW ON PAINT {|o,p|FPaint(o,p)}
    ...
    FUNCTION FPaint( o, lpDis )

    LOCAL drawInfo := hwg_Getdrawiteminfo( lpDis )
    LOCAL hDC := drawInfo[ 3 ], x1 := drawInfo[ 4 ], y1 := drawInfo[ 5 ], x2 := drawInfo[ 6 ], y2 := drawInfo[ 7 ]

    IF o:oFont != Nil
    hwg_Selectobject( hDC, o:oFont:handle )
    ENDIF
    IF o:tcolor != NIL
    hwg_Settextcolor( hDC, o:tcolor )
    ENDIF

    hwg_Rectangle( hDC, x1, y1, x2-1, y2-1 ) // Drawing a border

    hwg_Settransparentmode( hDC, .T. )
    hwg_Drawtext( hDC, o:title, x1+2, y1+2, x2, y2, o:nStyleDraw )
    hwg_Settransparentmode( hDC, .F. )

    RETURN NIL

    You may create a pen of any color and thickness to draw the border, or you may draw a rounded border with hwg_Roundrect().

    Regards, Alexander

     
  • Alexander S.Kresin

    But it is better to use the new BOARD control, because the code is absolutely the same under Windows and Linux GTK:
    ...
    @ 20, 20 BOARD oBoa SIZE 80, 26 ON PAINT {|o,h|FPaint(o,h)}
    oBoa:title := "Input"
    ...
    FUNCTION FPaint( o, h )

    IF o:oFont != Nil
    hwg_Selectobject( h, o:oFont:handle )
    ENDIF

    hwg_Rectangle( h,0, 0, o:nWidth-1, o:nHeight-1 )

    IF o:tcolor != NIL
    hwg_Settextcolor( h, o:tcolor )
    ENDIF

    hwg_Settransparentmode( h, .T. )
    hwg_Drawtext( h, o:title, 2, 2, o:nWidth, o:nHeight )
    hwg_Settransparentmode( h, .F. )

    RETURN NIL

     

    Last edit: Alexander S.Kresin 2023-08-17
  • José M. C. Quintas

    I use BOARD solution
    Thanks.

     
  • José M. C. Quintas

    Now 2 problem with that BOARD code:
    1) control:Title := "xxx" do not update screen
    2) adding control:refresh() draw over previous text, never clear old text

     
  • Alexander S.Kresin

    Yes, you need to call :Refresh() to update the control.
    What about the second punkt, I just added the TRANSPARENT flag to HBoard command. If it is used, the old text will be erased while refreshing.
    Or you may add hwg_fillrect() call to FPaint() to fill the background with desired color.

    Regards, Alexander.

     
  • José M. C. Quintas

    Using latest SVN version ok
    Thanks
    Note: attachment is before latest SVN

     
  • Alexander S.Kresin

    I've made some changes in HBoard fynctionality to improve and simplify its architecture, the TRANSPARENT clause is removed.
    you may add to the code above a line:
    oBoa:extStyle := WS_EX_TRANSPARENT

    or replace all the code with the following:

    @ 20, 20 BOARD oBoa SIZE 80, 26
    @ 0, 0 DRAWN oSay SIZE 80, 26 TEXT "Input"
    oSay:tBorderColor := 0 // Set the border color

    To change the label text you can with the:
    oSay:Settext("new_text")

    BTW, a short explanation of HBoard and HDrawn is here: http://www.kresin.ru/notes/index_en.php?b=blog_en&n=6

     

    Last edit: Alexander S.Kresin 2023-11-02

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.