bobm
New Member
Posts: 7
|
Post by bobm on Jan 7, 2022 15:54:20 GMT -5
I've sorted the records in my database by the first field (Name). I'm displaying the fields in each record, and would like to display Name in a different color than the rest of the fields. Can it be done? Here's a sample of my code.
PRINT #ListFile, " Name: "; TRIM$(SortRec$ (b, 1)) PRINT #ListFile, " Address: "; TRIM$(SortRec$ (b, 2))
|
|
|
Post by tsh73 on Jan 7, 2022 16:36:24 GMT -5
You better be more specific. You want it red - where? 1) on a LB form? 2) on some kind of document/printed report? as for (1) I could recommend this thread libertybasiccom.proboards.com/thread/1797/enhance-windows-controls(printing to a graphicbox could be low-tech option, but it'll be a picture - no ability to edit/copy to clipboard etc) as for (2) I would probably create HTML or RTF output, using string manipulation to output required bits and pieces. (EDIT code you just posted outputs plain text. By definition plain text has no provision for font, size and color )
|
|
bobm
New Member
Posts: 7
|
Post by bobm on Jan 7, 2022 17:04:32 GMT -5
It is a text file I'm displaying inside a text box on my screen, so I guess I'll have to find another way, using your suggestions.
Thanks, Bob
|
|
|
Post by Walt Decker on Jan 7, 2022 17:12:09 GMT -5
If you want it printed in an edit control or LB's text editor, it can not be done. You would have to use a rich edit control. You can do it directly to a form window; however, that requires a knowledge of API.
If you want to send it directly to a host printer, that can not be done with LB's LPRINT functions. There are dlls available that will do it; however they are not free. DDOC.dll comes to mind.
|
|
|
Post by Walt Decker on Jan 8, 2022 10:39:31 GMT -5
You might try using synchronized list boxes for each column. See THIS POSTAnother option is to use synchronized multi-line text boxes.
|
|
bobm
New Member
Posts: 7
|
Post by bobm on Jan 10, 2022 16:56:00 GMT -5
Thanks, Walt. I'll check out THIS POST. Whew! I can see this is not going to be simple.
|
|
|
Post by Walt Decker on Jan 10, 2022 18:01:26 GMT -5
Well, not haveing access to the callback function does complicate things. Most MS controls support a user-drawn style that will allow the programmer to customize the look and behavior of controls, however, LB does NOT and CAN NOT support that style. Therefore, to support a user-draw style the programmer will have to create a sub-class DLL for the specific control or controls.
If you need additional help, just ask.
|
|
|
Post by Rod on Jan 11, 2022 5:54:20 GMT -5
You can change textbox text color. It isn't my favourite thing to do, changing the background color is simpler. To change the text color we need to step outside Liberty and use a bit of API.
nomainwin
'|---------- Red Text Controls ----------| ForegroundColor$="red" TextboxColor$="darkblue"
statictext #red.st1,"Red on darkblue", 10, 10, 100, 17 textbox #red.tb1,10, 30, 100, 25
stylebits #red,0,_WS_VISIBLE,0,0 open "Red window" for window_popup as #red
'|-------- green Text Controls -------| ForegroundColor$="darkgreen" TextboxColor$="green"
statictext #green.st1,"Darkgreen on green", 120, 10, 100, 17 textbox #green.tb1,120, 30, 100, 25
stylebits #green,0,_WS_VISIBLE,0,0 open "Green window" for window_popup as #green
'|-------- Normal Text Controls ---------|
'Open the mainGUI WindowWidth = 250 WindowHeight = 160 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
TextboxColor$="" 'default ForegroundColor$="" 'default
statictext #1.st1,"Normal", 10, 70, 50, 17 textbox #1.tb1,10, 90, 100, 25
open "Main GUI" for window as #1 print #1, "font ms_sans_serif 8" print #1, "trapclose [quit.1]"
'Move the controls from the 'color' windows to the main GUI. ' Parent Child call setParent hWnd(#1) , hWnd(#red.st1) call setParent hWnd(#1) , hWnd(#red.tb1) call setParent hWnd(#1) , hWnd(#green.st1) call setParent hWnd(#1) , hWnd(#green.tb1)
#red.tb1 "123" #green.tb1 "123" #1.tb1 "123" wait
[quit.1] close #green close #red close #1 END
SUB setParent parent,child calldll #user32, "SetParent",_ child as ulong,_ parent as ulong,_ r as long END SUB
If you just wanted to change the background color and show or hide color changes you can do that natively.
'set the foreground and background colors 'these apply to the window and all controls BackgroundColor$ = "darkblue" ForegroundColor$ = "black" WindowWidth = 550 WindowHeight = 410 'override the BackgroundColor$ for the textbox TextboxColor$ = "red" textbox #main.textbox1, 30, 20, 100, 20 TextboxColor$ = "blue" textbox #main.textbox2, 30, 60, 100, 20 TextboxColor$ = "yellow" textbox #main.textbox3, 30, 100, 100, 20 TextboxColor$ = "green" textbox #main.textbox4, 30, 100, 100, 20 button #main.button,"Click Me", [clicked],UL,30, 140,100,20 open "untitled" for dialog as #main #main "trapclose [quit]" 'hide the fourth textbox #main.textbox4 "!hide" [main.inputLoop] 'wait here for input event wait
[clicked] 'toggle hidden textbox if clicked then #main.textbox3 "!hide" #main.textbox4 "!show" #main.textbox4 "!setfocus" clicked=0 else #main.textbox4 "!hide" #main.textbox3 "!show" #main.textbox3 "!setfocus" clicked=1 end if wait
[quit] close #main end
|
|
|
Post by Walt Decker on Jan 11, 2022 9:05:36 GMT -5
You can change textbox text color. It isn't my favourite thing to do, changing the background color is simpler. To change the text color we need to step outside Liberty and use a bit of API. He is asking about listboxes not edit controls.
He wants to change only one word, not the entire string.
|
|
|
Post by Rod on Jan 11, 2022 10:28:04 GMT -5
A name field in a database. I assume each field will have its own textbox. Not sure a record would ever present as a complete string. The OP can clarify what he really wants.
|
|
bobm
New Member
Posts: 7
|
Post by bobm on Jan 13, 2022 18:16:32 GMT -5
I thought I had posted a reply to clarify what I'm trying to do, but I can't find it, so I'll try again:
"I have a database of records, each record contains a name, address, etc.. My program sorts the records by name, transfers the records to a text file, and displays (not prints) each record in a text box, with each field on a separate line. I want to display the name field in a different color than the rest of the fields. I understand I can't do this, because I'm using a text box. Is there any other way to do this, which is fairly straightforward?"
I hope this helps.
Thanks, Bob
|
|
bobm
New Member
Posts: 7
|
Post by bobm on Jan 13, 2022 18:24:05 GMT -5
In re-reading what I just posted I see I wasn't clear about displaying the records in a text box. What I should have said is that I'm displaying all the records in the same text box.
Thanks, Bob
|
|
|
Post by Brandon Parker on Jan 13, 2022 21:59:15 GMT -5
This would be one way to do what you are looking for. If you have any questions about how it works just ask.
Just keep pressing the "Post Data" button until the information goes off the bottom of the GraphicBox. This will help demonstrate the reasoning for the "myRecords" segment that is constantly overwritten. All of the awesomeness happens in the printRecord subroutine.
If you want to change the text being posted, you will need to enter three items separated by the "|" (the pipe character) into the #Main.txtInput TextBox.
NoMainWin Global count : count = 1 WindowWidth = 500 WindowHeight = 300 GraphicBox #Main.gBoxText, 5, 5, (WindowWidth - 25), (WindowHeight - 80) TextBox #Main.txtInput, 5, (WindowHeight - 70), (WindowWidth - 110), 25 Button #Main.btnInput, "Post Data", btnPostText, UL, (WindowWidth - 95), (WindowHeight - 70), 75, 25 Open "Example Colors" For Window As #Main #Main "TrapClose quit" #Main.gBoxText "Down; Fill White; Flush Background" #Main.gBoxText "AutoResize" #Main.gBoxText "VertScrollbar On 0 10000" #Main.gBoxText "Place 5 15; Color Black" #Main.gBoxText "|Name Degree Favorite Language" #Main.gBoxText "Flush myRecords" #Main.txtInput "Brandon Parker|Computer Science|Liberty BASIC" Wait
Sub quit handle$ Close #handle$ End End Sub
Sub printRecord handle$, text$ firstWord$ = Word$(text$, 1, "|") secondWord$ = Word$(text$, 2, "|") thirdWord$ = Word$(text$, 3, "|") firstColumn$ = "Name " secondColumn$ = "Degree " #handle$ "StringWidth? firstColumn$ firstColumn" #handle$ "StringWidth? secondColumn$ secondColumn"
#handle$ "StringWidth? firstWord$ widthFirst" #handle$ "StringWidth? secondWord$ widthSecond"
#handle$ "PosXY xPos yPos" #handle$ "Color Red" #handle$ "|";firstWord$
#handle$ "Place ";(xPos + firstColumn);" ";yPos;"; Color Black"
#handle$ "|";secondWord$
#handle$ "Place ";(xPos + firstColumn + secondColumn);" ";yPos #handle$ "|";thirdWord$
#Main.gBoxText "Flush myRecords"
#handle$ "PosXY xPos yPos" #handle$ "Place 5 ";yPos #Main.txtInput "Everyone Else ";count;"|Computer Science|Liberty BASIC" count = (count + 1) End Sub
Sub btnPostText handle$ #Main.txtInput "!Contents? myText$" Call printRecord "#Main.gBoxText", myText$ End Sub
{:0)
Brandon Parker
|
|
|
Post by Brandon Parker on Jan 14, 2022 9:06:04 GMT -5
You could even take it a step forward and allow the two colors to be passed into the printRecord subroutine as shown in the example below.
NoMainWin Global count : count = 1 WindowWidth = 500 WindowHeight = 300 GraphicBox #Main.gBoxText, 5, 5, (WindowWidth - 25), (WindowHeight - 80) TextBox #Main.txtInput, 5, (WindowHeight - 70), (WindowWidth - 110), 25 Button #Main.btnInput, "Post Data", btnPostText, UL, (WindowWidth - 95), (WindowHeight - 70), 75, 25 Open "Example Colors" For Window As #Main #Main "TrapClose quit" #Main.gBoxText "Down; Fill White; Flush Background" #Main.gBoxText "AutoResize" #Main.gBoxText "VertScrollbar On 0 10000" #Main.gBoxText "Place 5 15; Color Black" #Main.gBoxText "|Name Degree Favorite Language" #Main.gBoxText "Flush myRecords" #Main.txtInput "Brandon Parker|Computer Science|Liberty BASIC" Wait
Sub quit handle$ Close #handle$ End End Sub
Sub printRecord handle$, text$, color1$, color2$ firstWord$ = Word$(text$, 1, "|") secondWord$ = Word$(text$, 2, "|") thirdWord$ = Word$(text$, 3, "|") firstColumn$ = "Name " secondColumn$ = "Degree " #handle$ "StringWidth? firstColumn$ firstColumn" #handle$ "StringWidth? secondColumn$ secondColumn"
#handle$ "StringWidth? firstWord$ widthFirst" #handle$ "StringWidth? secondWord$ widthSecond"
#handle$ "PosXY xPos yPos" #handle$ "Color ";color1$ #handle$ "|";firstWord$
#handle$ "Place ";(xPos + firstColumn);" ";yPos;"; Color ";color2$
#handle$ "|";secondWord$
#handle$ "Place ";(xPos + firstColumn + secondColumn);" ";yPos #handle$ "|";thirdWord$
#Main.gBoxText "Flush myRecords"
#handle$ "PosXY xPos yPos" #handle$ "Place 5 ";yPos #Main.txtInput "Everyone Else ";count;"|Computer Science|Liberty BASIC" count = (count + 1) End Sub
Sub btnPostText handle$ #Main.txtInput "!Contents? myText$" Call printRecord "#Main.gBoxText", myText$, "Red", "Black" End Sub
{:0)
Brandon Parker
|
|
|
Post by Brandon Parker on Jan 14, 2022 9:35:27 GMT -5
Here is another expanded version that attempts to remove some artifacts that start occurring when the number of records gets decently large in the relatively small GraphicBox. I might do some more experimenting...
NoMainWin Global count : count = 1
Global numRecords : numRecords = 1000 Global scrollbarHeight : scrollbarHeight = (16 * numRecords)
WindowWidth = 500 WindowHeight = 300 GraphicBox #Main.gBoxText, 5, 5, (WindowWidth - 25), (WindowHeight - 80) TextBox #Main.txtInput, 5, (WindowHeight - 70), (WindowWidth - 110), 25 Button #Main.btnInput, "Post Data", btnPostText, UL, (WindowWidth - 95), (WindowHeight - 70), 75, 25 Open "Example Colors" For Window As #Main #Main "TrapClose quit" #Main.gBoxText "Down; Fill White; Flush Background" #Main.gBoxText "AutoResize" #Main.gBoxText "VertScrollbar On 0 ";scrollbarHeight #Main.gBoxText "Place 5 15; Color Black" #Main.gBoxText "|Name Degree Favorite Language" #Main.gBoxText "Flush myRecords" #Main.txtInput "Brandon Parker|Computer Science|Liberty BASIC"
For i = 0 To numRecords Call btnPostText "#Main.btnInput" Next i
Wait
Sub quit handle$ Close #handle$ End End Sub
Sub printRecord handle$, text$, color1$, color2$ firstWord$ = Word$(text$, 1, "|") secondWord$ = Word$(text$, 2, "|") thirdWord$ = Word$(text$, 3, "|") firstColumn$ = "Name " secondColumn$ = "Degree " #handle$ "StringWidth? firstColumn$ firstColumn" #handle$ "StringWidth? secondColumn$ secondColumn"
#handle$ "StringWidth? firstWord$ widthFirst" #handle$ "StringWidth? secondWord$ widthSecond"
#handle$ "PosXY xPos yPos" #handle$ "Color ";color1$ #handle$ "|";firstWord$
#handle$ "Place ";(xPos + firstColumn);" ";yPos;"; Color ";color2$
#handle$ "|";secondWord$
#handle$ "Place ";(xPos + firstColumn + secondColumn);" ";yPos #handle$ "|";thirdWord$
#Main.gBoxText "Flush myRecords"
#handle$ "PosXY xPos yPos" #handle$ "Home; Color White; BackColor White; PosXY halfWidth halfHeight" #handle$ "Place 5 ";yPos #handle$ "BoxFilled ";(halfWidth * 2);" ";(scrollbarHeight * 2) #Main.txtInput "Everyone Else ";count;"|Computer Science|Liberty BASIC" count = (count + 1) End Sub
Sub btnPostText handle$ #Main.txtInput "!Contents? myText$" Call printRecord "#Main.gBoxText", myText$, "DarkBlue", "Black" End Sub
{:0)
Brandon Parker
|
|