Re: label at runtime
Posted: Fri Oct 20, 2017 9:02 am
It does not work
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://www.hmgforum.com/
Code: Select all
/*
* HMG - Harbour Win32 GUI library Demo
*
* Copyright 2008 Roberto Lopez <mail.box.hmg@gmail.com>
* http://www.hmgforum.com//
*/
#include "hmg.ch"
Function Main
Local aRows [20] [3]
aRows [1] := {'Simpson','Homer','555-5555'}
aRows [2] := {'Mulder','Fox','324-6432'}
aRows [3] := {'Smart','Max','432-5892'}
aRows [4] := {'Grillo','Pepe','894-2332'}
aRows [5] := {'Kirk','James','346-9873'}
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE 'HMG Demo' ;
MAIN
DEFINE TAB Tab_1 ;
AT 10,10 ;
WIDTH 600 ;
HEIGHT 400 ;
VALUE 1 ;
TOOLTIP 'Tab Control'
PAGE 'Page 1'
@ 100,250 BUTTON Button_1 CAPTION "Add Label On Page 4" WIDTH 150 HEIGHT 50 ACTION Make_label()
@ 180,250 BUTTON Button_2 CAPTION "Release Label On Page 4" WIDTH 150 HEIGHT 50 ACTION IF (IsControlDefined (NewLabel2 , Form_1) , DoMethod('Form_1','NewLabel2','Release') , Nil )
END PAGE
PAGE 'Page &2'
DEFINE RADIOGROUP R1
ROW 100
COL 100
OPTIONS { '1','2','3' }
VALUE 1
END RADIOGROUP
END PAGE
PAGE 'Page 3'
@ 100,250 SPINNER Spinner_1 ;
RANGE 0,10 ;
VALUE 5 ;
WIDTH 100 ;
TOOLTIP 'Range 0,10' ;
ON CHANGE PlayBeep()
END PAGE
PAGE 'Page 4'
@ 50,50 GRID Grid_1 ;
WIDTH 200 ;
HEIGHT 330 ;
HEADERS {'Last Name','First Name','Phone'} ;
WIDTHS {140,140,140};
ITEMS aRows ;
VALUE 1
END PAGE
END TAB
END WINDOW
Form_1.Center
Form_1.Activate
Return Nil
***********************
FUNCTION Make_label()
define label NewLabel2
parent Form_1
row 150
col 300
backColor {96,96,96}
value "BAR"
height 80
width 30
end label
//_AddTabControl ( TabName , ControlName , ParentForm , PageNumber , Row , Col )
_AddTabControl ( 'Tab_1' , 'NewLabel2' , 'Form_1' , 4 , 150 , 300 )
RETURN
Code: Select all
<WindowName>.<ControlName>.AddControl ( ControlName , nPagenumber , nRow , nCol )
Marek can post the code he usedmol wrote: ↑Wed Nov 11, 2020 10:11 am hI!
I found a bug in BosTaurus BT_DrawTextEx function
I want to print centered text rotated by 90 deg.
But, when changing length of text , it's position is not centered in vertical axis, it's always always positioned at the begin row, bet column of text is changed.
I think it should be opaque
Code: Select all
#include <hmg.ch>
*----------
function main
DEFINE WINDOW F1 ;
AT 0,0 ;
WIDTH 700 HEIGHT 700 ;
TITLE 'Draw text sample' ;
MAIN ;
backcolor {225,255,255} ;
ON PAINT DoTest()
DEFINE MAIN MENU OF F1
DEFINE POPUP "tEST"
MENUITEM "Test" action NIL
END POPUP
END MENU
END WINDOW
CENTER WINDOW F1
ON KEY ESCAPE OF F1 ACTION F1.RELEASE
ACTIVATE WINDOW F1
return
*----------------------
function DoTest
local nMiddleRow
local nMiddleCol
LOCAL hDC, BTstruct
hDC := BT_CreateDC ("F1", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
nMiddleRow := F1.Height/2
nMiddleCol := F1.Width/2
// print cross in the middle of the form
DRAW LINE IN WINDOW F1 at nMiddleRow, 0 to nMiddleRow, F1.Width PENCOLOR RED PENWIDTH 1
DRAW LINE IN WINDOW F1 at 0, nMiddleCol to F1.Height, nMiddleCol PENCOLOR RED PENWIDTH 1
//print vertical margins
DRAW LINE IN WINDOW F1 at nMiddleRow-201, nMiddleCol-201 to nMiddleRow+201, nMiddleCol-201 PENCOLOR {0,128,0} PENWIDTH 1
DRAW LINE IN WINDOW F1 at nMiddleRow-201, nMiddleCol+201 to nMiddleRow+201, nMiddleCol+201 PENCOLOR {0,128,0} PENWIDTH 1
// draw text in normal - horizontal orientation
// left aligned
BT_DrawTextEx(hDC,;
nMiddleRow-200, nMiddleCol-200,; // row, col
400, 20,; // width, height
"Normal, horizontal oriented, left aligned text",;
"ARIAL", 12,;
{0,128,0}, {255,255,224},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_LEFT + BT_TEXT_TOP,;
BT_TEXT_NORMAL_ORIENTATION)
// draw text in normal - horizontal orientation
// center aligned
BT_DrawTextEx(hDC,;
nMiddleRow-170, nMiddleCol-200,; // row, col
400, 20,; // width, height
"Normal, horizontal oriented, centered text",;
"ARIAL", 12,;
{0,128,0}, {255,255,224},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_CENTER + BT_TEXT_TOP,;
BT_TEXT_NORMAL_ORIENTATION)
// draw text in normal - horizontal orientation
// right aligned
BT_DrawTextEx(hDC,;
nMiddleRow-140, nMiddleCol-200,; // row, col
400, 20,; // width, height
"Normal, horizontal oriented, right aligned text",;
"ARIAL", 12,;
{0,128,0}, {255,255,224},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_RIGHT + BT_TEXT_TOP,;
BT_TEXT_NORMAL_ORIENTATION)
//print horizontal margins
DRAW LINE IN WINDOW F1 at nMiddleRow-201, nMiddleCol-201 to nMiddleRow-201, nMiddleCol+201 PENCOLOR {255,128,0} PENWIDTH 1
DRAW LINE IN WINDOW F1 at nMiddleRow+201, nMiddleCol-201 to nMiddleRow+201, nMiddleCol+201 PENCOLOR {255,128,0} PENWIDTH 1
// draw text in vertical orientation
// left aligned
BT_DrawTextEx(hDC,;
nMiddleRow+200, nMiddleCol-200,; // row, col
400, 20,; // width, height
"Vertical oriented,left aligned text",;
"ARIAL", 9,;
{255,0,0}, {255,255,128},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_LEFT + BT_TEXT_TOP,;
BT_TEXT_VERTICAL_ASCENDANT)
// draw text in vertical orientation
// center aligned
BT_DrawTextEx(hDC,;
nMiddleRow+200, nMiddleCol-180,; // row, col
400, 20,; // width, height
"Vertical oriented, center aligned text",;
"ARIAL", 9,;
{255,0,255}, {255,255,128},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_CENTER + BT_TEXT_TOP,;
BT_TEXT_VERTICAL_ASCENDANT)
// the same coordinates as above, but longer text
BT_DrawTextEx(hDC,;
nMiddleRow+200, nMiddleCol-180,; // row, col
400, 20,; // width, height
"Vertical oriented, center aligned text - transparent - which is longer - drawn somewhere",;
"ARIAL", 8,;
{255,0,255}, {255,255,128},;
BT_TEXT_TRANSPARENT + BT_TEXT_BOLD,;
BT_TEXT_CENTER + BT_TEXT_TOP,;
BT_TEXT_VERTICAL_ASCENDANT)
// draw text in vertical orientation
// right aligned
BT_DrawTextEx(hDC,;
nMiddleRow+200, nMiddleCol+200,; // row, col
400, 20,; // width, height
"Vertical oriented, right aligned text",;
"ARIAL", 9,;
{0,0,255}, {255,255,128},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD,;
BT_TEXT_RIGHT + BT_TEXT_TOP,;
BT_TEXT_VERTICAL_ASCENDANT)
// tho only one way to print vertical aligned
// centered text
w := BT_DrawTextSize(hDC,"VERTICAL ALIGNED CENTERED TEXT", "ARIAL", 10, BT_TEXT_BOLD + BT_TEXT_ITALIC)
BT_DrawTextEx(hDC,;
nMiddleRow-200 + w[1]/2 + 400/2, nMiddleCol -w[2]/2,;
400, 20,;
"VERTICAL ALIGNED CENTERED TEXT - OK",;
"ARIAL", 10, {255,0,0}, {224,224,224},;
BT_TEXT_OPAQUE + BT_TEXT_BOLD + BT_TEXT_ITALIC,;
BT_TEXT_LEFT+BT_TEXT_TOP,;
BT_TEXT_VERTICAL_ASCENDANT)
BT_DeleteDC (BTstruct)
return
with#define BT_TEXT_CENTER 6
and try to start your sample with above modification#define BT_TEXT_CENTER 1