May 10, 2024, 06:02:45 AM

News:

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


Edit Control Caret

Started by jay, September 13, 2007, 09:07:22 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jay

Greetings Everyone,

My problem lies in the edit control and the caret position in the edit control.  At start up I want to display in the edit box the word To and then have
the caret positioned 1 space after the word To.
My research leads me to the CONTROLCMD d1, 1,@EDSETSELECTION,3,-1 command but I am not familiar on where or how to properly place it.

I am starting off with a simple dialog box d1 with a single edit for simplicity with the Controlcmd command placed in the OnInitDialog.  This doesn't
seem to work as the words To are highlighted, another feature I would like to remove for the time being.
I am going to try to place this properly so here goes nothing
Here is my code:

DIALOG d1
CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@EDIT,"Edit1",53,78,195,19,0x50800000,1

SHOWDIALOG d1
run = 1
WAITUNTIL run = 0

CLOSEDIALOG d1,@IDOK

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
SETCONTROLTEXT(d1, 1, "To ")
CONTROLCMD d1, 1,@EDSETSELECTION,3,-1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
'EditBox 1

ENDSELECT
ENDSELECT
RETURN
ENDSUB


Thank you for your time.

Sorry if this is not in the right area...  Still learning    :-\

GWS

Hi Jay,

That's a strange one I've not seen before.  I hardly ever use dialogs myself, I always stick to windows.
Usually I'd put the 'To ' in a text box to the left of the edit box - leaving that free for a name or whatever you're going to type into it ..  :)

Here's as far as I got using a window:


window w
openwindow w,0,0,300,202,0,0,"Caption",&handler
CONTROL w,@EDIT,"",53,78,195,24,@CTEDITLEFT,1

SETCONTROLTEXT w, 1, "To "

setwindowcolor w, rgb(10,120,170)
CONTROLCMD w, 1,@EDSETSELECTION,3,-1
setfocus w,1



run = 1
WAITUNTIL run = 0

CLOSEWINDOW w

end

SUB handler
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w
CASE @IDCLOSEWINDOW
closewindow w
run = 0
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
'EditBox 1

ENDSELECT
ENDSELECT
RETURN
ENDSUB


That seems to work, but it doesn't answer why your dialog won't do the same.  Note I had to put the editbox statements in the main block of code rather than the initialising section - couldn't get it to perform otherwise ..  :)

Maybe other folk might have a solution .. :)

Graham
Tomorrow may be too late ..

GWS

Back again ..  :)

Strangely, it works fine in Creative ..


DEF d1:DIALOG

DIALOG d1,0,0,300,202,@CAPTION|@SYSMENU,0,"Caption",handler

CONTROL d1,"E,,53,78,195,19,0,1"

showdialog d1
SETCONTROLTEXT d1, 1, "To "
CONTROLCMD d1, 1,@EDSETSELECTION,3,-1

run=1
WAITUNTIL run = 0

CLOSEDIALOG d1
END

SUB handler
SELECT @CLASS
    CASE @IDINITDIALOG
        CENTERWINDOW d1
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN



all the best, :)

Graham
Tomorrow may be too late ..

jay

Thanks Graham

I did see that instead of putting the lines SETCONTROLTEXT d1, 1, "To " and CONTROLCMD d1, 1,@EDSETSELECTION,3,-1 in the @IDINITDIALOG
you moved them outside of that and put them below the SHOWDIALOG d1.  I tried that in EBasic and sure enough if worked fine.  INTERESTING.

The problem now comes from when I took that idea and applied it to a bigger application that I am working on where I am calling on the dialog from
the main application and I get the word "To" in the correct edit box but the cursor isn't set where I want it to be set and the word "To" is highlighted

I don't know why it won't work when I put it in the @IDINITDIALOG of my dialog. Hmmmm.

So now I am calling a dialog from a dialog.  I would post some  code but I got to get to work.  When I get home I will post some of what I am doing
and go from there if the problem isn't solved.

Once again your idea worked but it didn't work when I applied it to my bigger app of a dialog calling a dialog.  Again I say thanks...  :)

billhsln

Just wondering, is the 'To ', supposed to be default text that would always appear in the field?  If so, why not just make it a Static and in the program where you check if the field has been changed, automatically add the 'To ' to the field.


CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
                        IF @NOTIFYCODE = @ENCHANGE THEN var = "To " + GETCONTROLTEXT(d1,1)


Just a thought,
Bill
When all else fails, get a bigger hammer.

jay

Hi Bill

The "to" or "To" is suppose to be part of what I am trying to accomplish.  I need it in the dialog to help in my project
Thanks for your help and suggestion though.   :)

I do not know why this works but I solved it earlier today and now I have a chance to post it.  :o
Hope somebody besides me can use it.


DIALOG d1
DIALOG d2
DEF a:int

CREATEDIALOG d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@BUTTON,"Call Dialog",115,91,70,20,0x50000000,1

CREATEDIALOG d2,0,0,300,150,0x80C80080,d1,"Caption",&d2_handler
CONTROL d2,@EDIT,"Edit1",57,91,187,20,0x50800000,2
CONTROL d2,@STATIC,"Called Dialog",115,40,70,20,0x5000010B,3


run = 1
SHOWDIALOG d1

WAITUNTIL run = 0
run = 0
CLOSEDIALOG d1

END

SUB d1_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
run = 0
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
CASE 1
IF @NOTIFYCODE = 0
'Button was pressed.
GOSUB OpenDialog
'DOMODAL (d2,d1)
'SETCONTROLTEXT(d2, 2, "To ")
'CONTROLCMD d2, 2,@EDSETSELECTION,3,-1

ENDIF
ENDSELECT
ENDSELECT
RETURN
ENDSUB






SUB d2_handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d2
a = 1
/* Initialize any controls here */
CASE @IDCLOSEWINDOW
CLOSEDIALOG d2,@IDOK

CASE @IDCONTROL
SELECT @CONTROLID
CASE 2
IF @IDKEYDOWN AND a = 1
SETCONTROLTEXT(d2, 2, "to ")
CONTROLCMD d2, 2,@EDSETSELECTION,3,-1
a = 0
ENDIF
/* respond to edit notifications here */
ENDSELECT
ENDSELECT
RETURN
ENDSUB



SUB OpenDialog
DOMODAL (d2,d1)
'SETCONTROLTEXT(d2, 2, "To ")
'CONTROLCMD d2, 2,@EDSETSELECTION,3,-1
ENDSUB




Let's kill the fatted calf and celebrate!!!    ;D