Form tool class (4) Whether the scroll bar appears

In the development, there are some commonly used methods. It is troublesome to find the previously written ones every time. If you write them yourself, you are doing repetitive work, so there is always a small tool class and you can add content at any time.

4. Whether the scroll bar appears in the winform control static class  FormTools (public static class FormTools)

        private const int HSCROLL = 0x100000;
        private const int VSCROLL = 0x200000;
        private const int STYLE = -16;

        [DllImport("user32", CharSet = CharSet.Auto)]
        private static extern int GetWindowLong(IntPtr hwnd, int nIndex);

        /// <summary>
        /// Whether the vertical scroll bar appears
        /// </summary>
        /// <param name="ctrl">Control to be tested</param>
        /// <returns>true appears, false does not appear</returns>
        public static bool IsVScrolVisible(this Control ctrl)
        {
            if (!ctrl.IsHandleCreated)
                return false;

            return (GetWindowLong(ctrl.Handle, STYLE) & VSCROLL) != 0;
        }

        /// <summary>
        /// Whether the horizontal scroll bar appears
        /// </summary>
        /// <param name="ctrl">Control to be tested</param>
        /// <returns>true appears, false does not appear</returns>
        public static bool IsHScrolVisible(this Control ctrl)
        {
            if (!ctrl.IsHandleCreated)
                return false;
            return (GetWindowLong(ctrl.Handle, STYLE) & HSCROLL) != 0;
        }

transfer

            var isHScrol = flowLayoutPanel1.IsHScrolVisible();
            var isVScrol = flowLayoutPanel1.IsVScrolVisible();

Reference article https://blog.csdn.net/ltolll/article/details/7637995

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325627401&siteId=291194637