Home All Groups Group Topic Archive Search About

Scrollbars on Textbox -- how can I hide them?

Author
5 Mar 2009 2:04 AM
Stan Hilliard
I have a multiline textbox with V and H scrollbars. The amount of text
varies.  But the scrollbars are always present whether they are needed
or not. How can I hide or make the scrollbars go away when they are
not needed?

Author
5 Mar 2009 2:57 AM
Lorin
when will you know when they are not needed?

Show quoteHide quote
"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote in message
news:n1cuq4la3gjggc0jg2b5b05gqrd5s2sttb@4ax.com...
>I have a multiline textbox with V and H scrollbars. The amount of text
> varies.  But the scrollbars are always present whether they are needed
> or not. How can I hide or make the scrollbars go away when they are
> not needed?
Author
5 Mar 2009 3:24 AM
Stan Hilliard
On Wed, 4 Mar 2009 18:57:47 -0800, "Lorin" <lor***@hotmail.com> wrote:
>"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote in message
>news:n1cuq4la3gjggc0jg2b5b05gqrd5s2sttb@4ax.com...
>>I have a multiline textbox with V and H scrollbars. The amount of text
>> varies.  But the scrollbars are always present whether they are needed
>> or not. How can I hide or make the scrollbars go away when they are
>> not needed?

>when will you know when they are not needed?

I don't know but the scrollbars "know" when they are not needed
because their slider buttons disappear, leaving only the unneeded bars
themselves. I am thinking that perhaps someone has found a solution to
this.

Stan Hilliard
Author
5 Mar 2009 3:04 AM
Bill McCarthy
Hi Stan,

You can mess with this yourself, determining max text lines etc, but really
it is a lot easier just to use a RichTextBox and get the experience you want
straight out of the box.


Show quoteHide quote
"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote in message
news:n1cuq4la3gjggc0jg2b5b05gqrd5s2sttb@4ax.com...
>I have a multiline textbox with V and H scrollbars. The amount of text
> varies.  But the scrollbars are always present whether they are needed
> or not. How can I hide or make the scrollbars go away when they are
> not needed?
Author
5 Mar 2009 4:10 AM
Stan Hilliard
Thanks Bill, I tested a richtextbox control and it seems to be exactly
what I need.
Stan Hilliard

On Thu, 5 Mar 2009 14:04:57 +1100, "Bill McCarthy" <TPASoft.com Are
Identity Thieves> wrote:
Show quoteHide quote
>Hi Stan,
>You can mess with this yourself, determining max text lines etc, but really
>it is a lot easier just to use a RichTextBox and get the experience you want
>straight out of the box.


>"Stan Hilliard" <usenetreplyMS@samplingplansNOTSPAM.com> wrote in message
>news:n1cuq4la3gjggc0jg2b5b05gqrd5s2sttb@4ax.com...
>>I have a multiline textbox with V and H scrollbars. The amount of text
>> varies.  But the scrollbars are always present whether they are needed
>> or not. How can I hide or make the scrollbars go away when they are
>> not needed?
Author
5 Mar 2009 4:18 AM
C Kevin Provance
"Bill McCarthy" <I am stalking TPASoft.com> wrote in message
news:edXRTAUnJHA.5228@TK2MSFTNGP02.phx.gbl...
| Hi Stan,
|
| You can mess with this yourself, determining max text lines etc, but
really
| it is a lot easier just to use a RichTextBox and get the experience you
want
| straight out of the box.

Yeah, that's a great idea

/SARCASM

More overhead, another file to include with your setup.

Ignore McCarthy, his suggestions are about worthless.
Author
5 Mar 2009 4:37 AM
Ulrich Korndoerfer
Hi,

Stan Hilliard schrieb:
> I have a multiline textbox with V and H scrollbars. The amount of text
> varies.  But the scrollbars are always present whether they are needed
> or not. How can I hide or make the scrollbars go away when they are
> not needed?

The solution I use is following code (put it in a module):

Private Declare Function GetSystemMetrics Lib "user32" _
                         (ByVal Index As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
                         (ByVal hWnd As Long, ByVal wMsg As Long, _
                          ByVal wParam As Long, ByRef lParam As Any) As Long

Private Declare Function ShowScrollBar Lib "user32" _
                         (ByVal hWnd As Long, _
                          ByVal wBar As Long, _
                          ByVal bShow As Long) As Long

Private Const EM_GETLINECOUNT As Long = &HBA&

Private Const SB_VERT = 1
Private Const SB_HORZ = 0

Public Enum SystemMetricsConsts
   SM_CXSCREEN = 0:            SM_CYSCREEN = 1:            SM_CXDLGFRAME = 7
   SM_CYDLGFRAME = 8:          SM_CXFRAME = 32:            SM_CYFRAME = 33
   SM_CXBORDER = 5:            SM_CYBORDER = 6:            SM_CXEDGE = 45
   SM_CYEDGE = 46:             SM_CYCAPTION = 4:
SM_CYSMCAPTION = 51
   SM_CXMIN = 28:              SM_CYMIN = 29:              SM_CXMINTRACK
= 34
   SM_CYMINTRACK = 35:         SM_CXMAXTRACK = 59:         SM_CYMAXTRACK
= 60
   SM_CXFULLSCREEN = 16:       SM_CYFULLSCREEN = 17:
SM_MOUSEPRESENT = 19
   SM_CMOUSEBUTTONS = 43:      SM_SWAPBUTTON = 23:         SM_CXCURSOR = 13
   SM_CYCURSOR = 14:           SM_CXICON = 11:             SM_CYICON = 12
   SM_CXICONSPACING = 38:      SM_CYICONSPACING = 39:      SM_CXVSCROLL = 2
   SM_CYVSCROLL = 20:          SM_CYVTHUMB = 9:            SM_CYHSCROLL = 3
   SM_CXHSCROLL = 21:          SM_CXHTHUMB = 10:           SM_CYMENU = 15
   SM_CLEANBOOT = 67:          SM_CMONITORS = 80:
SM_CXDOUBLECLK = 36
   SM_CYDOUBLECLK = 37:        SM_CXDRAG = 68:             SM_CYDRAG = 69
   SM_CXMAXIMIZED = 61:        SM_CYMAXIMIZED = 62:
SM_CXMENUCHECK = 71
   SM_CYMENUCHECK = 72:        SM_CXMENUSIZE = 54:         SM_CYMENUSIZE
= 55
   SM_CXSIZE = 30:             SM_CYSIZE = 31:
SM_CXMINIMIZED = 57
   SM_CYMINIMIZED = 58:        SM_SLOWMACHINE = 73:        SM_SHOWSOUNDS
= 70
   SM_CXSMICON = 49:           SM_CYSMICON = 50:           SM_NETWORK = 63
   SM_MENUDROPALIGNMENT = 40:  SM_MOUSEWHEELPRESENT = 75:  SM_CXSMSIZE = 52
   SM_CYSMSIZE = 53:           SM_CXMINSPACING = 47:
SM_CYMINSPACING = 48
   SM_SAMEDISPLAYFORMAT = 81:  SM_SECURE = 44:             SM_ARRANGE = 56
   SM_XVIRTUALSCREEN = 76:     SM_YVIRTUALSCREEN = 77:
SM_CXVIRTUALSCREEN = 78
   SM_CYVIRTUALSCREEN = 79
End Enum 'SystemMetricConsts


'Hides or shows the scroll bars of a textbox. They are hidden, if the
textbox
'is big enough, otherwise they are shown. Code is from a tip from Thorsten
'Doerflers website at:

'http://www.vb-hellfire.de/knowlib/scrollhide.php

'- The textbox may have any border style
'- Can only hide/show scroll bars that have been set at design time with
'  the controls ScrollBars property! Use Vertical, Horizontal or both.
'- First call it on eg Form_Load on an *empty*, *unused* textbox to set
the magic up
'- Then call it in the textbox's Change event and after the textbox has
been resized!
'- Parent form and textbox container must have ScaleMode = vbPixels!
'- The parent form must have the same font the textbox has!

Public Sub gTextBoxScrollsAutoHide(ByRef TextBox As TextBox)
Const Appearance3D As Long = 1, BorderStyleSingle As Long = 1
Dim Lines As Long, InnerWidth As Long, InnerHeight As Long
Dim TextWidth As Long, HasHorizontal As Boolean, HasVertical As Boolean

With TextBox

   If .Appearance = Appearance3D Then
     InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
     InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)
   Else
     If .BorderStyle = BorderStyleSingle Then
       InnerWidth = .Width - 4&
       InnerHeight = .Height - 4&
     Else
       InnerWidth = .Width - 2&
       InnerHeight = .Height - 2&
     End If
   End If

   HasHorizontal = (.ScrollBars And vbHorizontal) = vbHorizontal
   HasVertical = (.ScrollBars And vbVertical) = vbVertical

   If HasHorizontal Then
     'If .Text contains more than 1 line (separated by vbCrLf),
     '.TextWidth returns the length of the longest line
     TextWidth = .Parent.TextWidth(.Text)
     If TextWidth > InnerWidth Then InnerHeight = InnerHeight -
GetSystemMetrics(SM_CYHSCROLL)
   End If

   'Vertical scrollbar
   If HasVertical Then
     Lines = SendMessage(.hWnd, EM_GETLINECOUNT, 0, ByVal 0&)
     If (.Parent.TextHeight("Xy") * (Lines)) > InnerHeight Then
       ShowScrollBar .hWnd, SB_VERT, True
       InnerWidth = InnerWidth - GetSystemMetrics(SM_CXVSCROLL)
     Else
       ShowScrollBar .hWnd, SB_VERT, False
     End If
   End If

   'Horizontal scrollbar
   If HasHorizontal Then ShowScrollBar .hWnd, SB_HORZ, TextWidth >
InnerWidth

End With
End Sub

gTextBoxScrollsAutoHide must be called in the textboxes change event and
at any place when/after a textbox has been resized. Also the textbox
container (normally a form) must have ScaleMode = vbPixels.

If you would like to see this in action, go to

<http://www.prosource.de/Downloads/indexe.html>

and download

<http://www.prosource.de/Downloads/VB_Binaries/CEvalTester1.2.zip>

Extract the archive and run CEvalCalculator.exe

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
Author
7 Mar 2009 4:29 PM
Stan Hilliard
On Thu, 05 Mar 2009 05:37:52 +0100, Ulrich Korndoerfer
<ulrich_wants_nospam@prosource.de> wrote:

Show quoteHide quote
>Hi,
>
>Stan Hilliard schrieb:
>> I have a multiline textbox with V and H scrollbars. The amount of text
>> varies.  But the scrollbars are always present whether they are needed
>> or not. How can I hide or make the scrollbars go away when they are
>> not needed?
>
>The solution I use is following code (put it in a module):
>
>Private Declare Function GetSystemMetrics Lib "user32" _
>                         (ByVal Index As Long) As Long
>
>Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
>                         (ByVal hWnd As Long, ByVal wMsg As Long, _
>                          ByVal wParam As Long, ByRef lParam As Any) As Long
>
>Private Declare Function ShowScrollBar Lib "user32" _
>                         (ByVal hWnd As Long, _
>                          ByVal wBar As Long, _
>                          ByVal bShow As Long) As Long
>
>Private Const EM_GETLINECOUNT As Long = &HBA&
>
>Private Const SB_VERT = 1
>Private Const SB_HORZ = 0
>
>Public Enum SystemMetricsConsts
>   SM_CXSCREEN = 0:            SM_CYSCREEN = 1:            SM_CXDLGFRAME = 7
>   SM_CYDLGFRAME = 8:          SM_CXFRAME = 32:            SM_CYFRAME = 33
>   SM_CXBORDER = 5:            SM_CYBORDER = 6:            SM_CXEDGE = 45
>   SM_CYEDGE = 46:             SM_CYCAPTION = 4:
>SM_CYSMCAPTION = 51
>   SM_CXMIN = 28:              SM_CYMIN = 29:              SM_CXMINTRACK
>= 34
>   SM_CYMINTRACK = 35:         SM_CXMAXTRACK = 59:         SM_CYMAXTRACK
>= 60
>   SM_CXFULLSCREEN = 16:       SM_CYFULLSCREEN = 17:
>SM_MOUSEPRESENT = 19
>   SM_CMOUSEBUTTONS = 43:      SM_SWAPBUTTON = 23:         SM_CXCURSOR = 13
>   SM_CYCURSOR = 14:           SM_CXICON = 11:             SM_CYICON = 12
>   SM_CXICONSPACING = 38:      SM_CYICONSPACING = 39:      SM_CXVSCROLL = 2
>   SM_CYVSCROLL = 20:          SM_CYVTHUMB = 9:            SM_CYHSCROLL = 3
>   SM_CXHSCROLL = 21:          SM_CXHTHUMB = 10:           SM_CYMENU = 15
>   SM_CLEANBOOT = 67:          SM_CMONITORS = 80:
>SM_CXDOUBLECLK = 36
>   SM_CYDOUBLECLK = 37:        SM_CXDRAG = 68:             SM_CYDRAG = 69
>   SM_CXMAXIMIZED = 61:        SM_CYMAXIMIZED = 62:
>SM_CXMENUCHECK = 71
>   SM_CYMENUCHECK = 72:        SM_CXMENUSIZE = 54:         SM_CYMENUSIZE
>= 55
>   SM_CXSIZE = 30:             SM_CYSIZE = 31:
>SM_CXMINIMIZED = 57
>   SM_CYMINIMIZED = 58:        SM_SLOWMACHINE = 73:        SM_SHOWSOUNDS
>= 70
>   SM_CXSMICON = 49:           SM_CYSMICON = 50:           SM_NETWORK = 63
>   SM_MENUDROPALIGNMENT = 40:  SM_MOUSEWHEELPRESENT = 75:  SM_CXSMSIZE = 52
>   SM_CYSMSIZE = 53:           SM_CXMINSPACING = 47:
>SM_CYMINSPACING = 48
>   SM_SAMEDISPLAYFORMAT = 81:  SM_SECURE = 44:             SM_ARRANGE = 56
>   SM_XVIRTUALSCREEN = 76:     SM_YVIRTUALSCREEN = 77:
>SM_CXVIRTUALSCREEN = 78
>   SM_CYVIRTUALSCREEN = 79
>End Enum 'SystemMetricConsts
>
>
>'Hides or shows the scroll bars of a textbox. They are hidden, if the
>textbox
>'is big enough, otherwise they are shown. Code is from a tip from Thorsten
>'Doerflers website at:
>
>'http://www.vb-hellfire.de/knowlib/scrollhide.php
>
>'- The textbox may have any border style
>'- Can only hide/show scroll bars that have been set at design time with
>'  the controls ScrollBars property! Use Vertical, Horizontal or both.
>'- First call it on eg Form_Load on an *empty*, *unused* textbox to set
>the magic up
>'- Then call it in the textbox's Change event and after the textbox has
>been resized!
>'- Parent form and textbox container must have ScaleMode = vbPixels!
>'- The parent form must have the same font the textbox has!
>
>Public Sub gTextBoxScrollsAutoHide(ByRef TextBox As TextBox)
>Const Appearance3D As Long = 1, BorderStyleSingle As Long = 1
>Dim Lines As Long, InnerWidth As Long, InnerHeight As Long
>Dim TextWidth As Long, HasHorizontal As Boolean, HasVertical As Boolean
>
>With TextBox
>
>   If .Appearance = Appearance3D Then
>     InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
>     InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)
>   Else
>     If .BorderStyle = BorderStyleSingle Then
>       InnerWidth = .Width - 4&
>       InnerHeight = .Height - 4&
>     Else
>       InnerWidth = .Width - 2&
>       InnerHeight = .Height - 2&
>     End If
>   End If
>
>   HasHorizontal = (.ScrollBars And vbHorizontal) = vbHorizontal
>   HasVertical = (.ScrollBars And vbVertical) = vbVertical
>
>   If HasHorizontal Then
>     'If .Text contains more than 1 line (separated by vbCrLf),
>     '.TextWidth returns the length of the longest line
>     TextWidth = .Parent.TextWidth(.Text)
>     If TextWidth > InnerWidth Then InnerHeight = InnerHeight -
>GetSystemMetrics(SM_CYHSCROLL)
>   End If
>
>   'Vertical scrollbar
>   If HasVertical Then
>     Lines = SendMessage(.hWnd, EM_GETLINECOUNT, 0, ByVal 0&)
>     If (.Parent.TextHeight("Xy") * (Lines)) > InnerHeight Then
>       ShowScrollBar .hWnd, SB_VERT, True
>       InnerWidth = InnerWidth - GetSystemMetrics(SM_CXVSCROLL)
>     Else
>       ShowScrollBar .hWnd, SB_VERT, False
>     End If
>   End If
>
>   'Horizontal scrollbar
>   If HasHorizontal Then ShowScrollBar .hWnd, SB_HORZ, TextWidth >
>InnerWidth
>
>End With
>End Sub
>
>gTextBoxScrollsAutoHide must be called in the textboxes change event and
>at any place when/after a textbox has been resized. Also the textbox
>container (normally a form) must have ScaleMode = vbPixels.
>
>If you would like to see this in action, go to
>
><http://www.prosource.de/Downloads/indexe.html>
>
>and download
>
><http://www.prosource.de/Downloads/VB_Binaries/CEvalTester1.2.zip>
>
>Extract the archive and run CEvalCalculator.exe

Thanks Ulrich for posting this program. I tested it and I does just
what I want and does it efficiently.

I did find what I think is one minor inaccuracy. I built a test VB6
project. It reads a text report from file and assigns it to the
modified textbox. The font is "Courier New", Scalemode is 3=Pixel. The
scrollbars automatically hide when not needed -- as intended.

But I discovered that the horizontal scrollbar comes up as an
empty/unhidden scrollbar without a button when the text is a few mouse
increments away from the edge of the text. I corrected that in the
code by subtracting 5 pixels from the calculated text width:

     TextWidth = .Parent.TextWidth(.Text) - 5

This works correctly now in my test project, but I don't know whether
the problem was specific to my particular text file or was systemic to
the code. 

Stan Hilliard
Author
8 Mar 2009 2:03 AM
Ulrich Korndoerfer
Hi,

Stan Hilliard schrieb:

>> With TextBox
>>
>>   If .Appearance = Appearance3D Then
>>     InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
>>     InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)

Replace above with:

   If .Appearance = Appearance3D Then
     If .BorderStyle = BorderStyleSingle Then
       InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
       InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)
     Else
       InnerWidth = .Width - 2&
       InnerHeight = .Height - 2&
     End If

Show quoteHide quote
> ...
> Thanks Ulrich for posting this program. I tested it and I does just
> what I want and does it efficiently.
>
> I did find what I think is one minor inaccuracy. I built a test VB6
> project. It reads a text report from file and assigns it to the
> modified textbox. The font is "Courier New", Scalemode is 3=Pixel. The
> scrollbars automatically hide when not needed -- as intended.
>
> But I discovered that the horizontal scrollbar comes up as an
> empty/unhidden scrollbar without a button when the text is a few mouse
> increments away from the edge of the text. I corrected that in the
> code by subtracting 5 pixels from the calculated text width:
>
>      TextWidth = .Parent.TextWidth(.Text) - 5
>
> This works correctly now in my test project, but I don't know whether
> the problem was specific to my particular text file or was systemic to
> the code. 

Probably my fault :-)

Please apply the change from above and try again (without your correction!)

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
Author
10 Mar 2009 9:37 PM
Stan Hilliard
On Sun, 08 Mar 2009 03:03:55 +0100, Ulrich Korndoerfer
<ulrich_wants_nospam@prosource.de> wrote:

Show quoteHide quote
>Hi,
>
>Stan Hilliard schrieb:
>
>>> With TextBox
>>>
>>>   If .Appearance = Appearance3D Then
>>>     InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
>>>     InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)
>
>Replace above with:
>
>   If .Appearance = Appearance3D Then
>     If .BorderStyle = BorderStyleSingle Then
>       InnerWidth = .Width - (GetSystemMetrics(SM_CXEDGE) * 2& + 2&)
>       InnerHeight = .Height - (GetSystemMetrics(SM_CYEDGE) * 2& + 2&)
>     Else
>       InnerWidth = .Width - 2&
>       InnerHeight = .Height - 2&
>     End If
>
>> ...
>> Thanks Ulrich for posting this program. I tested it and I does just
>> what I want and does it efficiently.
>>
>> I did find what I think is one minor inaccuracy. I built a test VB6
>> project. It reads a text report from file and assigns it to the
>> modified textbox. The font is "Courier New", Scalemode is 3=Pixel. The
>> scrollbars automatically hide when not needed -- as intended.
>>
>> But I discovered that the horizontal scrollbar comes up as an
>> empty/unhidden scrollbar without a button when the text is a few mouse
>> increments away from the edge of the text. I corrected that in the
>> code by subtracting 5 pixels from the calculated text width:
>>
>>      TextWidth = .Parent.TextWidth(.Text) - 5
>>
>> This works correctly now in my test project, but I don't know whether
>> the problem was specific to my particular text file or was systemic to
>> the code. 
>
>Probably my fault :-)
>
>Please apply the change from above and try again (without your correction!)

Thanks, I applied the correction.

That made it better. But in order to remove all possibility of a
visible blank scrollbar I had to subtract 1 pixel here:
     TextWidth = .Parent.TextWidth(.Text) - 1
and two pixels here:
     If (.Parent.TextHeight("Xy") * (Lines) - 2) > InnerHeight Then

I made observations by highlighting text in the textbox and then
carefully dragging the textbox to the highlighted text.

These are minor things but real. I could easily ignore them because it
is very unlikely that any future text will by chance be exactly one
pixel from the edge.

I was not familiar with the InnerWidth and InnerHeight properties. How
do they relate to ScaleWidth, ScaleHeight?

And what is the function of the ampersand in "2&" ?

Stan Hilliard
Author
11 Mar 2009 11:35 PM
Ulrich Korndoerfer
Hi,

Stan Hilliard schrieb:

Show quoteHide quote
> ...
> Thanks, I applied the correction.
>
> That made it better. But in order to remove all possibility of a
> visible blank scrollbar I had to subtract 1 pixel here:
>      TextWidth = .Parent.TextWidth(.Text) - 1
> and two pixels here:
>      If (.Parent.TextHeight("Xy") * (Lines) - 2) > InnerHeight Then
>
> I made observations by highlighting text in the textbox and then
> carefully dragging the textbox to the highlighted text.
>
> These are minor things but real. I could easily ignore them because it
> is very unlikely that any future text will by chance be exactly one
> pixel from the edge.

I suspect that this has to do with the way you are responding to text
box resize. Would you mind to post the resize code of your test project?

>
> I was not familiar with the InnerWidth and InnerHeight properties. How
> do they relate to ScaleWidth, ScaleHeight?
>

Those are not properties of the text box. Those are simple variables abd
are calculated.

> And what is the function of the ampersand in "2&" ?
>

It declares the type of the value as to be "Long". Normally (without the
ampersand) VB would create a value of type Integer. Then, when using the
value in an expression or as method parameter, it might has to convert
it to Long first. Using the ampersand may make the code some
femtoseconds faster :-)

However this really matters when one wants to avoid those nasty overflow
errors in expressions, eg:

Dim L As Long

L = 64000 * 2 'throws overflow error
L = 64000& * 2 'no error

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
Author
12 Mar 2009 12:09 AM
Ulrich Korndoerfer
Oops,

Ulrich Korndoerfer schrieb:

> ...
> However this really matters when one wants to avoid those nasty overflow
> errors in expressions, eg:
>
> Dim L As Long
>
> L = 64000 * 2 'throws overflow error
> L = 64000& * 2 'no error
>

Meant:

L = 32000 * 2 'throws overflow error
L = 32000& * 2 'no error

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/
Author
12 Mar 2009 12:13 PM
Stan Hilliard
On Thu, 12 Mar 2009 00:35:07 +0100, Ulrich Korndoerfer
<ulrich_wants_nospam@prosource.de> wrote:

Show quoteHide quote
>Hi,
>
>Stan Hilliard schrieb:
>
>> ...
>> Thanks, I applied the correction.
>>
>> That made it better. But in order to remove all possibility of a
>> visible blank scrollbar I had to subtract 1 pixel here:
>>      TextWidth = .Parent.TextWidth(.Text) - 1
>> and two pixels here:
>>      If (.Parent.TextHeight("Xy") * (Lines) - 2) > InnerHeight Then
>>
>> I made observations by highlighting text in the textbox and then
>> carefully dragging the textbox to the highlighted text.
>>
>> These are minor things but real. I could easily ignore them because it
>> is very unlikely that any future text will by chance be exactly one
>> pixel from the edge.
>
>I suspect that this has to do with the way you are responding to text
>box resize. Would you mind to post the resize code of your test project?

Private Sub Form_Resize()
    Text1.Width = Me.ScaleWidth    'in Form1.frm, an mdichild.
    Text1.Height = Me.ScaleHeight
    Dim txt As TextBox
    Set txt = Text1
    Call gTextBoxScrollsAutoHide(txt)
End Sub

Show quoteHide quote
>> I was not familiar with the InnerWidth and InnerHeight properties. How
>> do they relate to ScaleWidth, ScaleHeight?
>>
>
>Those are not properties of the text box. Those are simple variables abd
>are calculated.
>
>> And what is the function of the ampersand in "2&" ?
>>
>
>It declares the type of the value as to be "Long". Normally (without the
>ampersand) VB would create a value of type Integer. Then, when using the
>value in an expression or as method parameter, it might has to convert
>it to Long first. Using the ampersand may make the code some
>femtoseconds faster :-)
>
>However this really matters when one wants to avoid those nasty overflow
>errors in expressions, eg:
>
>Dim L As Long
>
>L = 64000 * 2 'throws overflow error
>L = 64000& * 2 'no error