mIRC Home    About    Download    Register    News    Help

Print Thread
#124947 13/07/05 12:07 AM
Joined: Jul 2005
Posts: 7
F
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2005
Posts: 7
Basically what I'm looking for help to do is to insert some text in an editbox when a button is clicked. I've gotten the button click down but I'm coming up at dead ends when I try to find a way to reference where the prompt currently is in the editbox.

For example say this is in the editbox:

You are a |friend.

(the pipe "|" is referrencing where the prompt is when the button is pushed)

And I added a button that would add a predefined text say, "good" so when it is pushed the text in the editbox now says:

You are a goodfriend.

(The space between good and friend would be added next by the user after pushing the button.)

How would I go about doing this?
Hope I've been clear and any help would be appreciated.

FTLNewsFeed

#124948 13/07/05 01:23 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Sorry but, there is no resource in mirc to make clear where the cursor inside the editbox line is at.

On another note, how did you detect a keypress? (ignore this question if you are refering to a custom window)

#124949 13/07/05 02:01 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
try my crude attempt:
i used $did().selend to get cursor pos

Code:
 
dialog edit {
  size -1 -1 200 100
  edit "",1, 1 1 200 20
  button "Insert",2,50 25 100 25
}
on *:dialog:edit:sclick:2:{
  var %insert = Good
  var %txt = $did(1),%len = $len(%txt)
  var %pos = $did(1).selend | ;cursor pos
  var %pos2 = %pos + 1 | ;offset
  var %precur = $left(%txt,%pos),%postcur = $mid(%txt,%pos2,$calc(%len - $len(%precur)))
  did -ra $dname 1 $iif(%precur,%precur) %insert $iif(%postcur,%postcur)

}
 


smile

anyways, i got a question of my own: how do i get what LINE the cursor is in, in a multiline editbox?

edit: Fixed so doesnt insert '0' when cursor is at the end or beggining

Last edited by arctangent; 13/07/05 02:06 AM.

- I AM -
#124950 13/07/05 04:30 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Now that i read the original post carefully, I realise he just might be talking about editboxes inside forms/dialogs since he actually said button clicks (i miss read that as keypress's). My refrence to no mirc resource was in refrence to the /EDITBOX command and $EDITBOX() identifier editbox's ie a channel/pm/window text box.

#124951 13/07/05 04:40 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
so mr pooh-ba.. ya gots any idea on how i could get the line number the cursor is at in a multiline editbox ( an edit box with multi and return styles set)? i wanna use it to make sumthin like a text editor, and i wanna be able to show the line number. smile thnx in advance


- I AM -
#124952 13/07/05 06:51 AM
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
Code:
alias cursor return $count($left($replace($lf $didtok($1,$2,10),$lf,$crlf),$did($1,$2).selstart),$crlf)


$cursor(name,id)

This should work for editboxes in which you have no empty lines as $didtok only returns up until the first empty line, and also the first ~ 950 characters. So it's not suitable for editboxes containing large amounts of text

Code:
alias _cursor {
  var %i = 0,%z,%x = $did($1,$2).selstart
  while (%i <= %x) { inc %z | inc %i $len($did($1,$2,%z) $+ ..) }
  return %z
}


$_cursor(name,id)

This should work for all editboxes

#124953 14/07/05 04:11 PM
Joined: Jul 2005
Posts: 7
F
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2005
Posts: 7
Thanks guys for your help. I was talking about a dialog for a custom window and arc's snippet worked perfectly but thank you Sigh for posting yours too. smile


Link Copied to Clipboard