Scrollbar mystery

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrNobody

    Scrollbar mystery

    I have a mystery where my scrollbar behaves differently from when I use it's
    slider/arrow keys compared to when I manipulate it's value with a
    onMouseWheel event...

    When I manipulate my scrollbar's controls (the slider or the arrow key) to
    go to the bottom, Once it reaches the bottom and cannot go any further I
    somehow lose 9 pixels of height, so when it refreshes my image the bottom 9
    pixels are clipped off.

    But if I use my MouseWheel event and wheel down to the bottom, it lines up
    perfectly. The MouseWheel event just takes the Delta and modified the
    scorllbar.Value property directly, not allowing it to go max or < min.

    So why does this happen?

    The only properties I change are the scrollbar's Maximum and Minimum values,
    where Minimum is 0 and Maximum is my image's height subtracted by the height
    of the client size rectangle. Everything else left at default.

  • MrNobody

    #2
    RE: Scrollbar mystery

    I created a small sample app which demonstrates the behavior I am talking
    about, since it's really hard for me to explain in text.

    create a WindowsApplicat ion and add my control like this:

    ScrollControl s = new ScrollControl() ;
    s.Location = new Point(10, 10);
    s.Size = new Size(250, 250);
    this.Controls.A dd(s);

    here is the control itself:

    public partial class ScrollControl : UserControl
    {
    Bitmap bmp;

    public ScrollControl()
    {
    InitializeCompo nent();

    bmp = new Bitmap(400, 400);
    Graphics g = Graphics.FromIm age(bmp);
    g.FillRectangle (Brushes.Black, 0, -vScrollBar1.Val ue, 400, 400);
    Pen p = new Pen(Brushes.Red , 10);
    g.DrawRectangle (p, 0, -vScrollBar1.Val ue, 400, 400);
    g.Dispose();

    vScrollBar1.Scr oll += new ScrollEventHand ler(vScrollBar1 _Scroll);
    }

    protected override void OnPaint(PaintEv entArgs e)
    {
    Point loc = new Point(0, -vScrollBar1.Val ue);
    e.Graphics.Draw ImageUnscaled(b mp, new Rectangle(loc, bmp.Size));
    }

    public override void Refresh()
    {
    this.OnPaint(ne w PaintEventArgs( this.CreateGrap hics(), new
    Rectangle(new Point(0, 0), this.ClientSize )));
    }

    protected override void OnSizeChanged(E ventArgs e)
    {
    vScrollBar1.Set Bounds(ClientRe ctangle.Right - vScrollBar1.Wid th,
    0, vScrollBar1.Wid th, ClientRectangle .Height);
    vScrollBar1.Max imum = bmp.Height - ClientSize.Heig ht;
    }

    void vScrollBar1_Scr oll(object sender, ScrollEventArgs e)
    {
    Refresh();
    }

    protected override void OnMouseWheel(Mo useEventArgs e)
    {
    int move = e.Delta / 10 * -1;
    if (move 0)
    {
    if (vScrollBar1.Va lue <= vScrollBar1.Max imum &&
    vScrollBar1.Val ue + move >= vScrollBar1.Max imum)
    vScrollBar1.Val ue = vScrollBar1.Max imum;
    else
    vScrollBar1.Val ue += move;
    }
    else
    {
    if (vScrollBar1.Va lue >= vScrollBar1.Min imum &&
    vScrollBar1.Val ue + move <= vScrollBar1.Min imum)
    vScrollBar1.Val ue = vScrollBar1.Min imum;
    else
    vScrollBar1.Val ue += move;
    }
    Refresh();
    }
    }


    Comment

    • Alex Fu

      #3
      Re: Scrollbar mystery

      int move = e.Delta * SystemInformati on.MouseWheelSc rollLines / 120;



      "MrNobody" <MrNobody@discu ssions.microsof t.comwrote in message
      news:9DAADFA2-91AF-402D-A22D-8CF4E24C8206@mi crosoft.com...
      >I created a small sample app which demonstrates the behavior I am talking
      about, since it's really hard for me to explain in text.
      >
      >
      protected override void OnMouseWheel(Mo useEventArgs e)
      {
      int move = e.Delta / 10 * -1;
      if (move 0)
      {
      if (vScrollBar1.Va lue <= vScrollBar1.Max imum &&
      vScrollBar1.Val ue + move >= vScrollBar1.Max imum)
      vScrollBar1.Val ue = vScrollBar1.Max imum;
      else
      vScrollBar1.Val ue += move;
      }
      else
      {
      if (vScrollBar1.Va lue >= vScrollBar1.Min imum &&
      vScrollBar1.Val ue + move <= vScrollBar1.Min imum)
      vScrollBar1.Val ue = vScrollBar1.Min imum;
      else
      vScrollBar1.Val ue += move;
      }
      Refresh();
      }
      }
      >
      >

      Comment

      • MrNobody

        #4
        Re: Scrollbar mystery



        "Alex Fu" wrote:
        int move = e.Delta * SystemInformati on.MouseWheelSc rollLines / 120;
        >
        >
        >
        Ah, that makes the mouse wheel scrolling alot smoother, thanks!

        Just that, it didnt solve the problem with the normal scroll bar control...

        notice how when you you the mouse wheel to go to the very bottom of the
        scroll area, you will be able to see the bottom red border?

        now try doing the same thing using the scroll bar control, either the down
        arrow or the thumb tab. It wont let you each the actual bottom so you can
        never see that bottom red border...

        why is that?

        Comment

        Working...