Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
Show a TextBox's vertical scrollbar only when it is necessary
.
C#
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowScrollBar(IntPtr hWnd, int wBar, [MarshalAs(UnmanagedType.Bool)] bool bShow);
User-Defined Types:
None.
Notes:
For reference:
SB_HORZ = 0
SB_VERT = 1
SB_CTL = 2
SB_BOTH = 3
Tips & Tricks:
Please add some!
Sample Code:
Please add some!
Alternative Managed API:
Do you know one? Please contribute it!
VB Signature:
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
When the form loads, set a hidden PictureBox's Font property to match the TextBox's.
In the TextBox's Change event handler, use the PictureBox's TextHeight function to see how tall the text is. If the text is too big to fit in the TextBox, we need to display the scrollbar. If the need for the scrollbar has changed, use the ShowScrollBar API function to show or hide it.
hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) _
As Long
Private Const SB_VERT = 1
Private Sub Form_Load()
' Make picHidden use the TextBox's font.
picHidden.Font = txtValue.Font
' Perform the initial startup check.
txtValue_Change
End Sub
Private Sub txtValue_Change()
Dim needs_scrollbar As Boolean
' See if we need the scrollbar.
needs_scrollbar = _
picHidden.TextHeight(txtValue.Text) > _
txtValue.Height - 60
' See if the need has changed.
If needs_scrollbar <> m_ScrollBarVisible Then
' Show or hide the scrollbar.
m_ScrollBarVisible = needs_scrollbar
ShowScrollBar txtValue.hwnd, SB_VERT, _
m_ScrollBarVisible
End If
End Sub
The ShowScrollBar API
9/10/2012 9:30:32 PM - Brian Ferguson-24.89.249.184
The ShowScrollBar API
9/10/2012 9:30:32 PM - Brian Ferguson-24.89.249.184
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
The ShowScrollBar API
9/10/2012 9:30:32 PM - Brian Ferguson-24.89.249.184
The ShowScrollBar API
9/10/2012 9:30:32 PM - Brian Ferguson-24.89.249.184
ByVal is a VB keyword that specifies a variable to be passed as a parameter BY VALUE. In other words, if the function or sub changes the value of the internal variable, it does not change the value of the external variable that was passed to it.
4/25/2007 3:19:55 AM - josep1er@cmich.edu-141.209.229.179
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).