Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-sizing a list box 1

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a form class which allows the controls within it to be re-sized at run time. In the Init() method of each of the control classes, the instance (for example a textbox) remembers its position, size and fontsize.

Then, when the form is re-sized, the form’s Resize() method visits each of the controls and recalculates the position &c.

This works fine; in the case of a Grid the column widths also need to be adjusted. So, in the same way, the grid’s Init() method remembers the width of each column. And the grid’s Resize() method then adjusts the columns.

In the case of a list box, which I sometimes use, the columns also need to be re-sized; however the Listbox does not seem to have a Resize() method, and the Column width properties are not stored separately. I realise that it is possible to parse the Columnwidths property, and then do the necessary arithmetic, but if anyone has been this way before I would be grateful for guidance.
 
The raw idea.
Code:
PUBLIC oFrm
oFrm=CREATEOBJECT("MyForm")
oFrm.Show()

DEFINE CLASS MyForm as Form
	Width0=375
	ADD OBJECT lst as MyListBox WITH ColumnCount=3,ColumnWidths="50,80,100",Width=300,RowSourceType=2,RowSource="cc",anchor=16+32+64+128
	PROCEDURE Load
		LOCAL lni
		CREATE CURSOR cc (ii I AUTOINC,aa C(10) DEFAULT SYS(2015),bb C(20) DEFAULT "Mambo number "+TRANSFORM(ii))
		FOR lni=1 TO 80
			APPEND BLANK
		NEXT
		GO TOP 
	ENDPROC
	PROCEDURE Init
		BINDEVENT(This,'Resize',This.lst,'Resize')
	ENDPROC 
ENDDEFINE

DEFINE CLASS MyListBox as ListBox
	DIMENSION ColWidths[1]
	ColWidths[1]=0
	Width0=0
	PROCEDURE StoreWidths
		LOCAL laCol[1]
		IF !EMPTY(This.ColumnWidths)
			DIMENSION This.ColWidths[ALINES(laCol,This.ColumnWidths,1+4,',')]
			ACOPY(laCol,This.ColWidths)
		ENDIF
		This.Width0=This.Width
	ENDPROC
	PROCEDURE Init
		This.StoreWidths
	ENDPROC
	PROCEDURE Resize
		LOCAL lnRatio,lni,lcStr
		IF This.Width0>0 AND !EMPTY(This.ColumnWidths)
			lnRatio=This.Width/This.Width0
			lcStr=''
			FOR lni=1 TO ALEN(This.ColWidths)
				lcStr=m.lcStr+RTRIM(STR(VAL(This.ColWidths[m.lni])*m.lnRatio))+','
			NEXT
			This.ColumnWidths=RTRIM(m.lcStr,1,',')
		ENDIF
	ENDPROC 
ENDDEFINE


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Thank you very much Vilhelm.

I have taken your code and built it into my Listbox (amlist) class, and my form class (amform), and it does the business.

I am not so familiar with the BINDEVENT() method, so I have chosen to handle that in my amform.resize() method. In that method I visit all the controls within the form anyway, so I have included additional code (for objects of class amlist) to call the amlist.resize() method.

And now that I have been introduced to the ALINES function, I may find a use for that elsewhere in my programs. You have been a great help.

Andrew



 
My pleasure [smile]
You may try adding
BINDEVENT(ThisForm,'Resize',This,'Resize')
in the init event of the amlist class, after This.StoreWidths instead of changing amform.resize()

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top