May 16, 2024, 02:46:56 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Setting font

Started by RichardB, April 27, 2010, 01:12:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RichardB

I am having difficulty setting the font for the edit control. I am sure I am missing something simple. I spent over an hour looking through the help and fourms. What am I overlooking?


autodefine "off"

def w1:window
def run:int
def label1:int
def l,t,w,h:int
def wininfo: int

wininfo = @MINBOX|@MAXBOX|@SIZE|@noautodraw
openwindow w1,0,0,350,350,wininfo,0,"Caption",&mainsub
centerwindow w1
setwindowcolor w1,rgb(192,192,192)
getclientsize w1,l,t,w,h


const menuexit = 20
beginmenu w1
menutitle "&file"
menuitem "e&xit",0,menuexit
endmenu

const label1 = 30
control w1,@edit,"",0,0,85,20,0,label1
setfont w1,"Courier New",8,400,0,label1

run = 1
waituntil run = 0
closewindow w1
end

'_________________________________________________________________________________
sub mainsub
select @class
case @idsize
'resize
case @idmousemove
mousemove()
case @idtimer
'if timer is needed

case @idmenupick
'________menu
select @menunum
case menuexit
run = 0
'@menunum
endselect
'_____end menu

case @idcontrol
'control handlers
select @controlid
'case button1
'@controlid
endselect

case @idclosewindow
run = 0

'@class
endselect

endsub
'_________________________________________________________________________________

sub mousemove
setcontroltext w1,label1, str$(@mousex) + " X " + str$(@mousey)
endsub

RichardB

Actually, the control was originally a static control (to be used as a label). I would rather avoid using edit controls if possible.

GWS

Richard,

I've never tried using constants for the control ID's - I usually just number them 1, 2, 3 .. etc.
It seems constants don't work too well.

Try;


control w1,@edit,"",0,10,195,40,0,1
setfont w1,"Courier New",18,600,0,1


That works .. or:


control w1,@static,"",0,10,195,40,0x200,1
setfont w1,"Courier New",18,600,0,1


The 0x200 centres text vertically ..  :)

all the best,

Graham

Tomorrow may be too late ..

LarryMc

My  previous responses were as a result of me having a "senior" moment, so I deleted them.

What was causing your problem with the @edit control was with label1

you defined label1 as an int which was okay in and of itself and what you normally do when identifying control ids.

but then you defined a CONST with the same name and set it to 30.

they are not the same animal.

the way I would have done it is

INT label1=30
or
INT label1
label1=30

no const statement is needed

Then it would work with either an edit control or a static control.

Sorry for my misleading info in the beginning

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

Graham mentioned:
QuoteThe 0x200 centres text vertically

You can also center, right align or left align the text using 0,1, or 2 in the right most digit.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RichardB

Thanks all. a constant seemed more natural to me as a control ID since there are few circumstances under which they change. I will stick with INTs. It works great now.

GWS

Quite a reasonable thought Richard ..  :)

I always use a variable myself, 'cos sometimes I would have :


FOR i = 1 to 10
   CONTROL ..................,i
NEXT i


.. which would give me 10 controls (if suitably spaced) with only 3 statements.  You can also place any font and colour settings inside the loop.

You could fill a screen with controls that way ..  ;D

best wishes, :)

Graham
Tomorrow may be too late ..

RichardB

I  can see how that technique could be useful in a database type program. I tend to  be a capricious programmer. I like to increment control IDs by 10 so I have plenty of available IDs should I want to add more controls.

LarryMc

RichardB
I always hated keeping track of ID numbers for controls and having to go back and renumber when I added something.

Ebasic has a way to end that problem forever and I've used it exclusively ever since it was added to the language.

ENUM  myids
   button1 =200
   button43
   edit15
   edit37
   static1
   edit_add
ENDENUM

If you don't put the =## they start at 1
You can go back and insert anytime you want to and they just automatically renumber themselves.
They all are INT.

And if you need a loop

For x= button1 to edit_add
  setfont w1,"Courier New",18,600,0,x
next x


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

Cool Larry  ;D
I dont know that this thing can work on this way ::)
Oh probably becose i to much used to Creative :-\

LarryMc

The feature was added in v1.62 of EBasic.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

That's really a remarkable way to do that.
I promise to use it too whenever i have the opportunity.  8)
Regards,

Peter B.

jerryclement

 ;D
Thanks Larry, I'm going to give it a try too!
JerryC
Jerry - Newbie from TN

LarryMc

what makes it really nice is being able to insert new controls and keep the names you give them in alphabetical order without having to go and renumber each time you add something.

It also insures you never duplicate a number.

I also use it when I create custom messages for a message handler (when I built custom controls) and also for custom user style flags at the same time.

I use it a lot with menu ids.

Once you get use to it you'll wonder how you ever got by without it.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library