private int AdjustScroll(Message m, int pos, int maxPos, bool horizontal)
        {
            switch (System.Windows.Forms.NativeMethods.Util.LOWORD(m.WParam))
            {
            case 0:
                if (pos <= 5)
                {
                    pos = 0;
                    return(pos);
                }
                pos -= 5;
                return(pos);

            case 1:
                if (pos >= (maxPos - 5))
                {
                    pos = maxPos;
                    return(pos);
                }
                pos += 5;
                return(pos);

            case 2:
                if (pos <= 100)
                {
                    pos = 0;
                    return(pos);
                }
                pos -= 100;
                return(pos);

            case 3:
                if (pos >= (maxPos - 100))
                {
                    pos = maxPos;
                    return(pos);
                }
                pos += 100;
                return(pos);

            case 4:
            case 5:
            {
                System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
                    cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
                    fMask  = 0x10
                };
                int fnBar = horizontal ? 0 : 1;
                if (!System.Windows.Forms.SafeNativeMethods.GetScrollInfo(new HandleRef(this, m.HWnd), fnBar, si))
                {
                    pos = System.Windows.Forms.NativeMethods.Util.HIWORD(m.WParam);
                    return(pos);
                }
                pos = si.nTrackPos;
                return(pos);
            }
            }
            return(pos);
        }
 private int ScrollThumbPosition(int fnBar)
 {
     System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
         fMask = 0x10
     };
     System.Windows.Forms.SafeNativeMethods.GetScrollInfo(new HandleRef(this, base.Handle), fnBar, si);
     return(si.nTrackPos);
 }
 internal void UpdateScrollInfo()
 {
     if (this.parent.IsHandleCreated && this.visible)
     {
         System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
             cbSize    = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
             fMask     = 0x17,
             nMin      = this.minimum,
             nMax      = this.maximum,
             nPage     = this.parent.AutoScroll ? this.PageSize : this.LargeChange,
             nPos      = this.value,
             nTrackPos = 0
         };
         UnsafeNativeMethods.SetScrollInfo(new HandleRef(this.parent, this.parent.Handle), this.Orientation, si, true);
     }
 }
 internal void UpdateScrollInfo()
 {
     if (this.parent.IsHandleCreated && this.visible)
     {
         System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
             cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
             fMask = 0x17,
             nMin = this.minimum,
             nMax = this.maximum,
             nPage = this.parent.AutoScroll ? this.PageSize : this.LargeChange,
             nPos = this.value,
             nTrackPos = 0
         };
         UnsafeNativeMethods.SetScrollInfo(new HandleRef(this.parent, this.parent.Handle), this.Orientation, si, true);
     }
 }
 internal void SetVirtualSizeNoInvalidate(Size value)
 {
     this.virtualSize = value;
     this.SetPositionNoInvalidate(this.position);
     System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
         fMask = 3,
         nMin  = 0,
         nMax  = Math.Max(base.Height, this.virtualSize.Height) - 1,
         nPage = base.Height
     };
     System.Windows.Forms.UnsafeNativeMethods.SetScrollInfo(new HandleRef(this, base.Handle), 1, si, true);
     si.fMask = 3;
     si.nMin  = 0;
     si.nMax  = Math.Max(base.Width, this.virtualSize.Width) - 1;
     si.nPage = base.Width;
     System.Windows.Forms.UnsafeNativeMethods.SetScrollInfo(new HandleRef(this, base.Handle), 0, si, true);
 }
Пример #6
0
 protected void UpdateScrollInfo()
 {
     if (base.IsHandleCreated && base.Enabled)
     {
         System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
             cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
             fMask  = 0x17,
             nMin   = this.minimum,
             nMax   = this.maximum,
             nPage  = this.LargeChange
         };
         if (this.RightToLeft == RightToLeft.Yes)
         {
             si.nPos = this.ReflectPosition(this.value);
         }
         else
         {
             si.nPos = this.value;
         }
         si.nTrackPos = 0;
         System.Windows.Forms.UnsafeNativeMethods.SetScrollInfo(new HandleRef(this, base.Handle), 2, si, true);
     }
 }
 public static extern bool GetScrollInfo(HandleRef hWnd, int fnBar, [In, Out] System.Windows.Forms.NativeMethods.SCROLLINFO si);
        private void CustomDraw(ref Message m)
        {
            TreeNode node;
            System.Windows.Forms.NativeMethods.NMTVCUSTOMDRAW lParam = (System.Windows.Forms.NativeMethods.NMTVCUSTOMDRAW) m.GetLParam(typeof(System.Windows.Forms.NativeMethods.NMTVCUSTOMDRAW));
            switch (lParam.nmcd.dwDrawStage)
            {
                case 0x10001:
                    node = this.NodeFromHandle(lParam.nmcd.dwItemSpec);
                    if (node != null)
                    {
                        int uItemState = lParam.nmcd.uItemState;
                        if (this.drawMode == TreeViewDrawMode.OwnerDrawText)
                        {
                            lParam.clrText = lParam.clrTextBk;
                            Marshal.StructureToPtr(lParam, m.LParam, false);
                            m.Result = (IntPtr) 0x12;
                            return;
                        }
                        if (this.drawMode == TreeViewDrawMode.OwnerDrawAll)
                        {
                            DrawTreeNodeEventArgs args;
                            using (Graphics graphics = Graphics.FromHdcInternal(lParam.nmcd.hdc))
                            {
                                Rectangle rowBounds = node.RowBounds;
                                System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
                                    cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
                                    fMask = 4
                                };
                                if (System.Windows.Forms.UnsafeNativeMethods.GetScrollInfo(new HandleRef(this, base.Handle), 0, si))
                                {
                                    int nPos = si.nPos;
                                    if (nPos > 0)
                                    {
                                        rowBounds.X -= nPos;
                                        rowBounds.Width += nPos;
                                    }
                                }
                                args = new DrawTreeNodeEventArgs(graphics, node, rowBounds, (TreeNodeStates) uItemState);
                                this.OnDrawNode(args);
                            }
                            if (!args.DrawDefault)
                            {
                                m.Result = (IntPtr) 4;
                                return;
                            }
                        }
                        OwnerDrawPropertyBag itemRenderStyles = this.GetItemRenderStyles(node, uItemState);
                        bool flag = false;
                        Color foreColor = itemRenderStyles.ForeColor;
                        Color backColor = itemRenderStyles.BackColor;
                        if ((itemRenderStyles != null) && !foreColor.IsEmpty)
                        {
                            lParam.clrText = ColorTranslator.ToWin32(foreColor);
                            flag = true;
                        }
                        if ((itemRenderStyles != null) && !backColor.IsEmpty)
                        {
                            lParam.clrTextBk = ColorTranslator.ToWin32(backColor);
                            flag = true;
                        }
                        if (flag)
                        {
                            Marshal.StructureToPtr(lParam, m.LParam, false);
                        }
                        if ((itemRenderStyles == null) || (itemRenderStyles.Font == null))
                        {
                            break;
                        }
                        System.Windows.Forms.SafeNativeMethods.SelectObject(new HandleRef(lParam.nmcd, lParam.nmcd.hdc), new HandleRef(itemRenderStyles, itemRenderStyles.FontHandle));
                        m.Result = (IntPtr) 2;
                        return;
                    }
                    m.Result = (IntPtr) 4;
                    return;

                case 0x10002:
                    if (this.drawMode != TreeViewDrawMode.OwnerDrawText)
                    {
                        break;
                    }
                    node = this.NodeFromHandle(lParam.nmcd.dwItemSpec);
                    if (node != null)
                    {
                        using (Graphics graphics2 = Graphics.FromHdcInternal(lParam.nmcd.hdc))
                        {
                            Rectangle bounds = node.Bounds;
                            Size size = TextRenderer.MeasureText(node.Text, node.TreeView.Font);
                            Point location = new Point(bounds.X - 1, bounds.Y);
                            bounds = new Rectangle(location, new Size(size.Width, bounds.Height));
                            DrawTreeNodeEventArgs e = new DrawTreeNodeEventArgs(graphics2, node, bounds, (TreeNodeStates) lParam.nmcd.uItemState);
                            this.OnDrawNode(e);
                            if (e.DrawDefault)
                            {
                                TreeNodeStates state = e.State;
                                Font font = (node.NodeFont != null) ? node.NodeFont : node.TreeView.Font;
                                Color color3 = (((state & TreeNodeStates.Selected) == TreeNodeStates.Selected) && node.TreeView.Focused) ? SystemColors.HighlightText : ((node.ForeColor != Color.Empty) ? node.ForeColor : node.TreeView.ForeColor);
                                if ((state & TreeNodeStates.Selected) == TreeNodeStates.Selected)
                                {
                                    graphics2.FillRectangle(SystemBrushes.Highlight, bounds);
                                    ControlPaint.DrawFocusRectangle(graphics2, bounds, color3, SystemColors.Highlight);
                                    TextRenderer.DrawText(graphics2, e.Node.Text, font, bounds, color3, TextFormatFlags.Default);
                                }
                                else
                                {
                                    using (Brush brush = new SolidBrush(this.BackColor))
                                    {
                                        graphics2.FillRectangle(brush, bounds);
                                    }
                                    TextRenderer.DrawText(graphics2, e.Node.Text, font, bounds, color3, TextFormatFlags.Default);
                                }
                            }
                        }
                        m.Result = (IntPtr) 0x20;
                        return;
                    }
                    return;

                case 1:
                    m.Result = (IntPtr) 0x20;
                    return;
            }
            m.Result = IntPtr.Zero;
        }
 private int ScrollThumbPosition(int fnBar)
 {
     System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
         fMask = 0x10
     };
     System.Windows.Forms.SafeNativeMethods.GetScrollInfo(new HandleRef(this, base.Handle), fnBar, si);
     return si.nTrackPos;
 }
        private int AdjustScroll(Message m, int pos, int maxPos, bool horizontal)
        {
            switch (System.Windows.Forms.NativeMethods.Util.LOWORD(m.WParam))
            {
                case 0:
                    if (pos <= 5)
                    {
                        pos = 0;
                        return pos;
                    }
                    pos -= 5;
                    return pos;

                case 1:
                    if (pos >= (maxPos - 5))
                    {
                        pos = maxPos;
                        return pos;
                    }
                    pos += 5;
                    return pos;

                case 2:
                    if (pos <= 100)
                    {
                        pos = 0;
                        return pos;
                    }
                    pos -= 100;
                    return pos;

                case 3:
                    if (pos >= (maxPos - 100))
                    {
                        pos = maxPos;
                        return pos;
                    }
                    pos += 100;
                    return pos;

                case 4:
                case 5:
                {
                    System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
                        cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.SCROLLINFO)),
                        fMask = 0x10
                    };
                    int fnBar = horizontal ? 0 : 1;
                    if (!System.Windows.Forms.SafeNativeMethods.GetScrollInfo(new HandleRef(this, m.HWnd), fnBar, si))
                    {
                        pos = System.Windows.Forms.NativeMethods.Util.HIWORD(m.WParam);
                        return pos;
                    }
                    pos = si.nTrackPos;
                    return pos;
                }
            }
            return pos;
        }
 internal void SetVirtualSizeNoInvalidate(Size value)
 {
     this.virtualSize = value;
     this.SetPositionNoInvalidate(this.position);
     System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
         fMask = 3,
         nMin = 0,
         nMax = Math.Max(base.Height, this.virtualSize.Height) - 1,
         nPage = base.Height
     };
     System.Windows.Forms.UnsafeNativeMethods.SetScrollInfo(new HandleRef(this, base.Handle), 1, si, true);
     si.fMask = 3;
     si.nMin = 0;
     si.nMax = Math.Max(base.Width, this.virtualSize.Width) - 1;
     si.nPage = base.Width;
     System.Windows.Forms.UnsafeNativeMethods.SetScrollInfo(new HandleRef(this, base.Handle), 0, si, true);
 }
Пример #12
0
        private void DoScroll(ScrollEventType type)
        {
            if (this.RightToLeft == RightToLeft.Yes)
            {
                switch (type)
                {
                case ScrollEventType.SmallDecrement:
                    type = ScrollEventType.SmallIncrement;
                    break;

                case ScrollEventType.SmallIncrement:
                    type = ScrollEventType.SmallDecrement;
                    break;

                case ScrollEventType.LargeDecrement:
                    type = ScrollEventType.LargeIncrement;
                    break;

                case ScrollEventType.LargeIncrement:
                    type = ScrollEventType.LargeDecrement;
                    break;

                case ScrollEventType.First:
                    type = ScrollEventType.Last;
                    break;

                case ScrollEventType.Last:
                    type = ScrollEventType.First;
                    break;
                }
            }
            int newValue = this.value;
            int oldValue = this.value;

            switch (type)
            {
            case ScrollEventType.SmallDecrement:
                newValue = Math.Max(this.value - this.SmallChange, this.minimum);
                break;

            case ScrollEventType.SmallIncrement:
                newValue = Math.Min((int)(this.value + this.SmallChange), (int)((this.maximum - this.LargeChange) + 1));
                break;

            case ScrollEventType.LargeDecrement:
                newValue = Math.Max(this.value - this.LargeChange, this.minimum);
                break;

            case ScrollEventType.LargeIncrement:
                newValue = Math.Min((int)(this.value + this.LargeChange), (int)((this.maximum - this.LargeChange) + 1));
                break;

            case ScrollEventType.ThumbPosition:
            case ScrollEventType.ThumbTrack:
            {
                System.Windows.Forms.NativeMethods.SCROLLINFO si = new System.Windows.Forms.NativeMethods.SCROLLINFO {
                    fMask = 0x10
                };
                System.Windows.Forms.SafeNativeMethods.GetScrollInfo(new HandleRef(this, base.Handle), 2, si);
                if (this.RightToLeft != RightToLeft.Yes)
                {
                    newValue = si.nTrackPos;
                    break;
                }
                newValue = this.ReflectPosition(si.nTrackPos);
                break;
            }

            case ScrollEventType.First:
                newValue = this.minimum;
                break;

            case ScrollEventType.Last:
                newValue = (this.maximum - this.LargeChange) + 1;
                break;
            }
            ScrollEventArgs se = new ScrollEventArgs(type, oldValue, newValue, this.scrollOrientation);

            this.OnScroll(se);
            this.Value = se.NewValue;
        }