Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is scrollbar hidden?

Is scrollbar hidden?

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hain
    wrote on last edited by
    #1

    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

    L A 2 Replies Last reply
    0
    • H hain

      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

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.


      1 Reply Last reply
      0
      • H hain

        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

        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • A Alan N

          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.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups