label at runtime
Moderator: Rathinagiri
Re: label at runtime
Here is working demo
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
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: label at runtime
It is very simple.
First define the control having the parent as the same window where the tab resides.
Then use the following method to add the control the the tab page.
First define the control having the parent as the same window where the tab resides.
Then use the following method to add the control the the tab page.
Code: Select all
<WindowName>.<ControlName>.AddControl ( ControlName , nPagenumber , nRow , nCol )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
Re: label at runtime
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
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
Re: label at runtime
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
Re: label at runtime
I prepared some code, maybe I'm wrong, but centering text is with bug.
Also, vertical orientation is bad.
Also, vertical orientation is bad.
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
- Attachments
-
- drawtextsample.jpg (65.36 KiB) Viewed 2621 times
Re: label at runtime
Hello Marek,
Thanks for your sample
Please replace in your header file BosTaurus.CH the following line
It should fix the text center alignment in the horizontal orientation.
Thanks for your sample
Please replace in your header file BosTaurus.CH the following line
with#define BT_TEXT_CENTER 6
and try to start your sample with above modification#define BT_TEXT_CENTER 1
It should fix the text center alignment in the horizontal orientation.
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein