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);
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
Edit by Dave 2012-09-11 d_a__v___e@hotmail.com
I had a lot of trouble with the above VB signature on a w7 vs2010 VM giving imbalanced stack errors, eventually got this working,
Signature:
<DllImport("user32")> _
Public Shared Function ShowScrollBar(ByVal hWnd As System.IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
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
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
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
10/29/2018 9:54:18 AM - -188.219.234.106
The ShowScrollBar API
10/29/2018 9:54:18 AM - -188.219.234.106
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
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
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
10/29/2018 9:54:18 AM - -188.219.234.106
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
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
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
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).