Textbox event

PatrikL

Member
Licensed User
Hi everybody,

I have question for skilled users. I want catch moment when inactive scrollbar in textbox goes to active (text is bigger then textbox).

I try found something in forum but I found only for table and this code (with modifications for textbox) dont work on textbox.

I want create special textbox with variable height according text amount.

Its possible?

Thanx

P.S. Sorry for my poor english.
 

ExcludeReality

Active Member
Licensed User
You can use StringHeight in ImageLib to get the height of the text, then compare it to the height of the textbox.
 

PatrikL

Member
Licensed User
That is nice, but StringHeight give me same value for "I" and also for "I want create special textbox with variable height according text amount."

StringHeight give me height of one line. But textbox have (in my case) more lines. I dont know how many. So I cant multiply height with lines count.

So StringHeight isnt solution for me.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I've been looking around the MSDN site at what options are available and the only thing I have come up with is that you could look to see if the ScrollBar is active and if so enlarge the Textbox.
The ScrollBar property is read/write so you could possibly use the door library to find out if the ScrollBar is present, if so enlarge the Textbox by one line and re-check. Continue enlarging the Textbox until the ScrollBar is no longer present or the maximum height is reached.
This is likely to cause some flickering of the control whilst it is being resized and so probably best to do this with the text box hidden and then display the Textbox once you have finished resizing it.

Regards,
RandomCoder
 

agraham

Expert
Licensed User
Longtime User
I'm afraid that the ScrollBars property doesn''t indicate whether the scroll bar is active or not, only whether it should be displayed or not. If it is to be displayed then it is shown without a slider if it is not active. The default for a multi-line textbox in Basic4ppc is for the vertical scroll bar only to be displayed.

I've been through all the methods and properties of a TextBox and I am afraid that I can see no way of detecting whether a scroll bar is active or not. I suspect that sending Windows messages to the underlying native control might be the only way of achieving that.
 

ExcludeReality

Active Member
Licensed User
That is nice, but StringHeight give me same value for "I" and also for "I want create special textbox with variable height according text amount."

StringHeight give me height of one line. But textbox have (in my case) more lines. I dont know how many. So I cant multiply height with lines count.

You have to take StringWidth into account.
For example, say the height of one line 15 pixels:
B4X:
If StringWidth > Textbox1.Width then
   StringHeight = StringHeight +15
End If

If StringHeight > Textbox1.Height then 'scrollbar is active

By doing this you add the height of one line every time the textbox moves to a new line.
You might need to experiment with the code to make it work properly.

-EDIT-
It actually seems to work fine without using StringWidth.
The only problem is that it ignores blank lines.
You can probably fix this by writing the text to a file, then reading the file line by line and counting the lines.
I attached a small example.
 

Attachments

  • ScrollbarDetection.sbp
    1.1 KB · Views: 322
Last edited:

PatrikL

Member
Licensed User
Hmm, I try Your example. Works fine if You use "Enter", but if text without new line reach end of textbox, dont work. :(

Its realy so hard detect if is scrollbar active or not? :( :( :(
 

PatrikL

Member
Licensed User
I found this page:

adf.ly - shrink your URLs and get paid!

But for me is impossible for implement (or use) in Basic4PPC. Please if somebody who understand what is on that page, please create for me example or dll, which I can use in Basic4PCC.

Thanks a lot.
 

PatrikL

Member
Licensed User
Nobody to create a small dll? Creating dll is for me high level.

This function for calculating multiline text size will be usefull for more users.

So please try create it.
 

PatrikL

Member
Licensed User
I tried to use htmlpanel to calculate the height of text. Unfortunately it does not work as I imagined. When you enter a very long word textbox wrap text, htmlpanel dont wrap and therefore the results are useless.

Therefore I would ask someone who has experience writing C language and libraries to help me and write the code applicable to Basic4PPC. Sample code is above.

Thanx a lot.

Or check my prog, maybe I have any misstake.
 

Attachments

  • panel2.sbp
    2.2 KB · Views: 230
Top