Autoscroll to bottom in EDITBOX

Moderator: Rathinagiri

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

Autoscroll to bottom in EDITBOX

Post by Clip2Mania » Mon Jun 30, 2014 11:42 am

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: 5181
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 141 times
Been thanked: 131 times
Contact:

Post by Rathinagiri » Mon Jun 30, 2014 3:30 pm

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
Been thanked: 1 time

Post by Clip2Mania » Tue Jul 01, 2014 7:45 am

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 95 times

User avatar
gfilatov
Posts: 519
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 8 times
Been thanked: 72 times
Contact:

Post by gfilatov » Tue Jul 01, 2014 9:20 am

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
Been thanked: 1 time

Post by Clip2Mania » Tue Jul 01, 2014 2:06 pm

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:

Post by Agil Abdullah » Mon Sep 29, 2014 10:07 am

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: 1906
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 317 times
Been thanked: 74 times
Contact:

Post by serge_girard » Mon Sep 29, 2014 1:21 pm

Thanks Gregory !

Serge

Javier Tovar
Posts: 1274
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México
Has thanked: 1 time
Been thanked: 2 times

Post by Javier Tovar » Mon Sep 29, 2014 4:26 pm

Gracias Gregory Filatov,

Excelente ejemplo! :)

Saludos

User avatar
esgici
Posts: 4363
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 246 times
Been thanked: 91 times
Contact:

Post by esgici » Sat Nov 01, 2014 11:57 pm

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