|
Post by bushrat on Jul 28, 2023 22:02:37 GMT -5
I can't find what I'm looking for anywhere so I have to ask...
How to simply change a font in a running program? Some results I want printed in a bigger bold size, other times just in the default font.
what's the simplest way to do this?
thanks
|
|
|
Post by Rod on Jul 29, 2023 1:41:23 GMT -5
It will depend on what type of control you wish to change. Also whether you wish to change all text in the control or just a portion. An example of what you want to do will get better advice. Meanwhile the help file says this about live font changes. www.libertybasicuniversity.com/lb4help/How_to_Specify_Fonts.htmGrahicboxes allow more flexibility and you can show and hide controls set at the start of the program but as I said we need to better understand the task.
|
|
|
Post by bushrat on Jul 29, 2023 2:43:45 GMT -5
I was looking for some sort of one line dynamic command that could be written just before a 'print' statement which allowed for font changing. I don't want to interact with anything to get a font change, and the font changes I'm after would be too numerous to go writing a dialog every time I wanted the change.
So I guess there's no way to get what I wanted.
Thanks for your reply.
|
|
|
Post by Walt Decker on Jul 29, 2023 8:33:12 GMT -5
NOT TESTED
' FUNCTION FN.SetFont(Ctrl$, FontName$, PntSize$, Bold$, Italic$) 'Ctrl$ = the control tag, e. g. #1.buttonok DQ$ = CHR$(34)
FontSpec$ = DQ$ + "!" + FontName$ + " " + PntSize$ + * " + Bold$ + " " + Italic$ + DQ$
#Ctrl$, FontSpec$
END FUNCTION '
For buttons you might have to drop the exclamation point in the FontSpec$ line. Changing the font in text boxes changes all text.
|
|
|
Post by tsh73 on Jul 29, 2023 9:04:31 GMT -5
bushrat, you really should explain what you want. For example, scenario 1 Your program prints to a minawin but some lines are more important so you output then in different font - impossibla as far as I know, all contents of mainwin has only one font scenario 2 you show some information, single screen is enough, you don't care about copying it with CtrlC as a text - you can print to graphicbox. Change colors, fonts. But only thing you get back is picture scenario 3 you need some output as a separate document to share with others, with font changes - then you can write HTML or RTF document HTML is pretty easy to write by hand RTF pronbably could be included as a RTF control via API You see? There are endless list of things you might want to do some of them doable for some workarounds could be divised
Don't give up just yet. Try to explain the problem.
|
|
|
Post by Rod on Jul 29, 2023 15:10:48 GMT -5
I can probably guess that we are discussing mainwin fonts and colours. Which don’t exist since we are meant to us the mainwin for debugging and development and the much more capable display controls for…. Display
|
|
|
Post by bushrat on Jul 29, 2023 18:15:43 GMT -5
Sincerely, I'm very grateful for all the advice you all provide whenever I've asked a question about LB, you are all very generous with your time.
That said, it's as if we are talking different languages when it comes to my problems and your explanations.
Here's the thing, apart from getting user input via a window at the start of my programs the user never interacts with the program again. My programs then run to completion with results being printed out at the end. I don't use graphics of any sort, I just get some input at the start to kick off the program then the program does its thing. I have dozens of programs with this 'structure' and they all run perfectly. It's when I want to do something a bit different that problems arise.
In reply to Rod, yeah, you guessed right I'm trying to change fonts in mainwin which apparently isn't possible.
What I'm beginning to realise is that I don't understood the environment in which LB programs are meant to be operating - I'm referring to 'mainwin' versus other running modes. I guess all my stuff runs in mainwin. Let me ask about program structure in general.
"... we are meant to use the mainwin for debugging and development and the much more capable display controls for…. Display" I don't really understand what that means - how is LB meant to be run? There's tons of stuff in the LB documentation about details of various windows but not much about how LB programs should be structured? or am I missing something? I imagine LB structure as in the following:
programs start in mainwin? need some input? call some dialog window go back to mainwin need some input? call some dialog window go back to mainwin etc...
that's the way I see LB program structure - perhaps I have it all wrong and LB programs are meant to be run entirely within some particular window.
I'll stop before I end up writing nonsense. But that's where I'm at.
Thanks again everyone.
|
|
|
Post by Walt Decker on Jul 29, 2023 18:38:44 GMT -5
Remember DOS? There was one window. You could change the text color but not the font. MAINWIN is basically a cut-down DOS window. It has no graphic user interface (GUI) although you can get input from it and send output to it. Therefore, if you want to display output in different fonts and sizes you need a GUI window. That is where the "form" windows come in. You put controls on them and manipulate the controls to do what you want.
Programs do not start in MAINWIN. They start when you begin writing code. Programs never go back to MAINWIN. They go to the end of the first function/sub called or the last WAIT statement.
The reason I say the above is this statement: NOMAINWIN. With that there is no MAINWIN displayed so how could the code flow got back to something that is not present?
Does that help?
|
|
|
Post by Rod on Jul 30, 2023 1:59:51 GMT -5
You are missing out on a huge amount of fun by sticking to mainwin. Lots of the demo programs use the mainwin but equally lots of them show you how GUI displays work. So play with the demos, try my new freeform lite program to place controls on a window. You take input in text boxes or from buttons and display output as text or graphics in text boxes or graphic boxes.
|
|
|
Post by tenochtitlanuk on Jul 30, 2023 5:58:14 GMT -5
An example to give you some ideas... It asks the user for one input, then prints the response in a mixture of fonts colours and sizes. Screen shows Result then prints to the default printer. nomainwin
WindowWidth = 800 WindowHeight = 740
UpperLeftX = 100 UpperLeftY = 200
' Ask user for input prompt "Tell me your name"; response$ if response$ ="" then response$ ="tenochtitlanuk"
' Create and fill in the required text, numbers, etc open "Page for viewing, saving or printing" for graphics_nsb as #wg
#wg "trapclose [quit]"
#wg "down"
' Demonstrate random colours and backgrounds.. for i =0 to 9 #wg "up ; goto "; 10 +i *25; " "; 20 +i *60 #wg "down"
' Invent a random colour rf =int( 256 *rnd( 1)): gf =int( 256 *rnd( 1)): bf =int( 256 *rnd( 1)) #wg "color "; rf; " "; gf; " "; bf ' Set background to its inverse colour. #wg "backcolor "; 255 -rf; " "; 255 -gf; " "; 255 -bf ' Set font size ( and/or style or name) #wg "font "; int( 10 +50 *rnd( 1))
#wg "\"; " "; i; " "; response$; " " next i
' print the resulting screen at desired width on default printer. ' Here 1600 means my 800 fits half paper width #wg "flush" #wg "print 1600"
' Save image of page for records or furter use. #wg "getbmp scr 1 1 800 700" bmpsave "scr", "output.bmp"
wait
[quit] close #wg
end
|
|
|
Post by xxgeek on Jul 30, 2023 10:19:15 GMT -5
I noticed in one of your other posts you were using statictext controls to display text on a window. So I put together a little demo to show that you can change fonts, their size and properties on the fly. You can use literal text or variables.
'xxgeek July 2023 'shows changing fonts and font size on the fly 'this is an example to show that statictext can be used to display changing fonts and font sizes on the fly. 'Changes to fonts and their size and properties can be made anywhere in the program 'first make a window with some statictext controls nomainwin WindowWidth=1000 WindowHeight=800 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 'no need to provide initial text for the static text, but it IS allowed statictext #test.st1, "Some initial text if desired",5,100,1000,60 statictext #test.st2, "",5,200,1000,50 statictext #test.st3, "",5,300,1000,50 statictext #test.st4, "",5,400,1000,50 statictext #test.st5,"",5,500,1000,50 statictext #test.st6, "",5,600,1000,50 testText$ = "The quick brown fox jumped over the lazy dog" ' using this variable below to show the text x=1 open "Test" for window as #test #test "trapclose [quit]" #test.st1 "!font arial 18 bold" 'Only statictext1 (#test.st1) will be seen until the first loop run (1 second)
'loop every second [looping] timer 1000,[loop] wait
[loop] 'using different fonts and increasing the size x=x+1 'loop counter if x > 10 then [enough] ' 10 loops #test.st1 "!font arial ";x*4;" underlined" 'font size increases with x #test.st1 "The Date Today is ";date$() #test.st2 "!font Verdana ";x*3;" bold" #test.st2 "The Time Now is ";time$() #test.st3 "!font gigi ";x*3;" italic" #test.st3 date$();" ";time$() 'prints date and time #test.st4 "!font Consolas ";x*2;" bold" #test.st4 "Working Directory = ";DefaultDir$ 'the dir this program is run from #test.st5 "!font sans seriff italic ";x*2;" bold" #test.st5 "Startup Directory = ";StartupDir$ 'the dir jbasic.exe or (if running the tkn or exe) where the renamed jbrun2.exe is run from #test.st6 "!font gigi ";x*2;" italic" #test.st6 testText$;" Timer Count = ";x 'prints the variable testText$ along with the value of x goto [looping]
[quit] close #test end
'program flow ends up here after 10 loops [enough] wait
|
|
|
Post by bushrat on Jul 30, 2023 18:48:43 GMT -5
Wow! it's gonna take a little while to digest all that stuff from you guys. I will run everything you've suggested and go through every line to get a handle on where I'm missing out. I really like working with LB and I've already solved a few problems I had earlier with 'mysterious' program halts by using your suggestions, particularly with the placement of wait statements, trapclose etc. great stuff! I actually know what I'm doing now.
thanks again to all.
|
|