Re: Win32Lib input box
Erik-Jan van Kampen wrote:
>
> Hello EUForum,
>
> I was trying to make an input box for numbers with Win32Lib that takes exactly
> 9 rows of 9 numbers in such a way that when you type in the numbers you will
> automatically go to the next line when you have entered 9 numbers. It must
> also
> not be possible to enter more than 9 rows.
Have a look at this demo
---------------------------------------
without warning
include win32lib.ew
integer win
sequence boxes
procedure KeyPress_boxes(integer self, integer event, sequence parms)
integer lPos
-- Only allow digits.
lPos = find(parms[1], "123456789")
if lPos = 0 then
-- Not a digit from 1-9, however allow
-- backspaces to be processed as normal
if parms[1] = VK_BACKSPACE then
return
end if
returnValue(-1)
return
end if
-- If there is already something in the box, just stay put.
if length(getText(self)) != 0 then
returnValue(-1) -- Don't replace already entered data
return
end if
-- Find out what is the next box to move to.
lPos = find(self, boxes)
if lPos != length(boxes) then
setFocus(boxes[lPos+1])
else
-- Last box gets special treatment.
setFocus(self)
end if
end procedure
procedure init()
integer lTextWidth
integer lMaxWidth
integer lMaxHeight
integer k
integer top
integer left
win = create(Window, "Nine by Nine", 0, 0, 0, 0, 0, 0)
setFont(win, "FixedSys", 16, {Bold,0,0,0,ANSI_CHARSET,0,0,0,0}) -- or any
other font
lMaxWidth = 0
for i = 1 to 9 do
lTextWidth = getTextWidth(win, sprintf("%d", i))
if lTextWidth > lMaxWidth then
lMaxWidth = lTextWidth
end if
end for
lMaxHeight = getTextHeight(win, "|") + 5
lMaxWidth += 5
-- Make the window big enough.
setClientRect(win, lMaxWidth * 9 + 15 + 15 + (3 * (9-1)),
lMaxHeight * 9 + 10 + 10 + (3 * (9-1))
)
-- Draw the boxes now
boxes = repeat(0, 81)
k = 1
top = 10
for i = 1 to 9 do
left = 15
for j = 1 to 9 do
boxes[k] = create(EditText, "", win, left, top, lMaxWidth,
lMaxHeight, 0)
k += 1
left += lMaxWidth + 3
end for
top += lMaxHeight + 3
end for
-- Set the same handler for each of the boxes.
setHandler( boxes, w32HKeyPress, routine_id("KeyPress_boxes"))
end procedure
init()
WinMain({win, boxes[1]}, Normal)
---------------------------------------
Hope this helps.
--
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell
|
Not Categorized, Please Help
|
|