Is scrollbar hidden?
-
I have RichTextBox with the ScrollBars property set to Both. In a forms-based program, I would like to be able to programatically determine if a given scroll bar--vertical or horizontal--is visible (i.e., showing or not, depending on the RichTextBox contents.) Thanks, Tom
-
I have RichTextBox with the ScrollBars property set to Both. In a forms-based program, I would like to be able to programatically determine if a given scroll bar--vertical or horizontal--is visible (i.e., showing or not, depending on the RichTextBox contents.) Thanks, Tom
Hi, AFAIK that will not be simple as there is no .NET support for it. I would suggest: - getting the Handle; - calling EnumChildWindows; - somehow recognizing which of those are scroll bars (don't recall how right now); - look at their visibility. That will take a lot of P/Invoke stuff; these prototypes may help:
public delegate bool LP\_EnumWindowsProc(IntPtr hWnd, IntPtr lParam); \[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)\] public static extern int EnumChildWindows(IntPtr hParent, LP\_EnumWindowsProc ewp, IntPtr lParam); \[DllImport("user32.dll", CallingConvention=CallingConvention.StdCall)\] public static extern bool IsWindowVisible(IntPtr hWnd);
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
I have RichTextBox with the ScrollBars property set to Both. In a forms-based program, I would like to be able to programatically determine if a given scroll bar--vertical or horizontal--is visible (i.e., showing or not, depending on the RichTextBox contents.) Thanks, Tom
Hi, There's an article on MSDN with VB code describing how this can be done by testing for the WS_HSCROLL and WS_VSCROLL bits in the window style retrieved with GetWindowLong. How To Detect If Scroll Bars Are Visible on a Control[^] and it is applicable to .Net as the underlying control is the same. Here's an excerpt from a C# test programme.
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
private const Int32 GWL_STYLE = -16;
private const Int32 WS_HSCROLL = 0x100000;
private const Int32 WS_VSCROLL = 0x200000;private void TestForSB(RichTextBox rtb) {
Int32 style = GetWindowLong(rtb.Handle, GWL_STYLE);
Boolean hasVertical = (style & WS_VSCROLL) != 0;
Boolean hasHorizontal = (style & WS_HSCROLL) != 0;
label1.Text = String.Format("Vertical: {0}, Horizontal: {1}", hasVertical, hasHorizontal);
}Alan.
-
Hi, There's an article on MSDN with VB code describing how this can be done by testing for the WS_HSCROLL and WS_VSCROLL bits in the window style retrieved with GetWindowLong. How To Detect If Scroll Bars Are Visible on a Control[^] and it is applicable to .Net as the underlying control is the same. Here's an excerpt from a C# test programme.
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
private const Int32 GWL_STYLE = -16;
private const Int32 WS_HSCROLL = 0x100000;
private const Int32 WS_VSCROLL = 0x200000;private void TestForSB(RichTextBox rtb) {
Int32 style = GetWindowLong(rtb.Handle, GWL_STYLE);
Boolean hasVertical = (style & WS_VSCROLL) != 0;
Boolean hasHorizontal = (style & WS_HSCROLL) != 0;
label1.Text = String.Format("Vertical: {0}, Horizontal: {1}", hasVertical, hasHorizontal);
}Alan.
Yes, that's much easier. :thumbsup:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.