Autoscroll to bottom in EDITBOX

Moderator: Rathinagiri

Post Reply
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Autoscroll to bottom in EDITBOX

Post by Clip2Mania »

I'm "filling up" an editbox (with vertical scrollbar) with data, which is over a hundred lines long, refreshing the display after every line that I add. The default behaviour is that you only see the x number of first lines (depending on height you defined).

Is there a way to have the editbox automatically scroll down when you add lines beyond the height of the editbox?
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Autoscroll to bottom in EDITBOX

Post by Rathinagiri »

Did you try this?

form.editbox.caretpos := len( form.editbox.value )
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Autoscroll to bottom in EDITBOX

Post by Clip2Mania »

Mr Rathinagiri,
Did you try this?
form.editbox.caretpos := len( form.editbox.value )
The caret-position is indeed at the end, but the editbox doesn't scroll to the bottom... :(

Adding piece of code attached.
Attachments
Scroll.zip
(1.32 KiB) Downloaded 406 times
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Autoscroll to bottom in EDITBOX

Post by gfilatov »

Clip2Mania wrote: Adding piece of code attached.
Hi,

Thanks for your sample code.

Please take a look for the working updated sample below. 8-)

Code: Select all

#include <hmg.ch>
#define CRLF chr(13)+chr(10)

function main()
local cSMsg:="Do Something"


DEFINE WINDOW MainForm;
	AT 90,90;
	WIDTH 780;
	HEIGHT 550;
  TITLE 'Inventory Renamer';
	MAIN;
	NOSIZE
	
	DEFINE MAIN Menu of MainForm
		DEFINE POPUP "File"
			MENUITEM "Select From List" ACTION DoList()
			SEPARATOR
			MENUITEM "Exit" ACTION ThisWindow.Release
		END POPUP
	END MENU

	DEFINE STATUSBAR 
		STATUSITEM cSMsg
		CLOCK
		DATE
	END STATUSBAR
	@ 005,005 EDITBOX Edit_1            ;
      WIDTH 760 HEIGHT 425 ;// READONLY    ;
			VALUE " ";
	    FONTCOLOR {000,000,255}           ;
		FONT "Courier New" SIZE 10 
	@ 440, 665 BUTTON bn_Go;
		OF MainForm;
		CAPTION "Rename";
		ACTION MsgInfo("Go!")
	@ 443, 10  LABEL lb_Stat ;
	  VALUE " ";
		WIDTH 650;
		TRANSPARENT
	
END WINDOW       

MainForm.Center
MainForm.Activate

return NIL

//-----------------------
function Dolist()
local cList, n, nTokens
local cStr:=""

if !file("list.txt")
   MsgInfo("Didn't find a list.txt")
	 return NIL
endif

cList:=memoread("list.txt")
nTokens:=numtoken(cList,CRLF)

MsgInfo("List is "+str(len(cList))+" bytes long"+ CRLF + str(nTokens)+" lines in the list")

For n := 1 to nTokens
  cDir:=token(cList,CRLF,n)
  cStr:=cStr+"File "+strzero(n,3)+" "+cDir+CRLF
  MainForm.Edit_1.Value:=cStr
  MainForm.Edit_1.Caretpos := len(MainForm.Edit_1.Value)-1
  do events
Next

INSERT_CTRL_END()

return NIL

//-------------------
function strzero(nNum,nLen)
return right(replicate("0",nLen)+ltrim(token(str(nNum),".",1)),nLen)

//-------------------
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

HB_FUNC( INSERT_CTRL_END )
{
	keybd_event(
		VK_CONTROL,	// virtual-key code
		0,		// hardware scan code
		0,		// flags specifying various function options
		0		// additional data associated with keystroke
	);

	keybd_event(
		VK_END	,	// virtual-key code
		0,		// hardware scan code
		0,		// flags specifying various function options
		0		// additional data associated with keystroke
	);

	keybd_event(
		VK_CONTROL,	// virtual-key code
		0,		// hardware scan code
		KEYEVENTF_KEYUP,// flags specifying various function options
		0		// additional data associated with keystroke
	);
}

#pragma ENDDUMP
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Clip2Mania
Posts: 99
Joined: Fri Jun 13, 2014 7:16 am
Location: Belgium

Re: Autoscroll to bottom in EDITBOX

Post by Clip2Mania »

Unfortunately, don't know any C myself ... :(
Thanks for this solution Grigory!
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Autoscroll to bottom in EDITBOX

Post by Agil Abdullah »

For me, it's very useful, coz not only reading text/memo but also showing line numbers at every line.

Thanks Gregory.
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Autoscroll to bottom in EDITBOX

Post by serge_girard »

Thanks Gregory !

Serge
There's nothing you can do that can't be done...
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Autoscroll to bottom in EDITBOX

Post by Javier Tovar »

Gracias Gregory Filatov,

Excelente ejemplo! :)

Saludos
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Autoscroll to bottom in EDITBOX

Post by esgici »

Clip2Mania wrote:Unfortunately, don't know any C myself ... :(
...
Hi Erik

I agree with you :arrow:

We need something like HMG_KeyPut() same as HB_KeyPut() :?

Happy HMG'ing :)
Viva INTERNATIONAL HMG :D
Post Reply