1

So I was using the code from this link,

how to get smartphone like scrolling for a winforms touchscreen app ( scrolling panel )

but I ran into an issue that in the form if the user clicks on a label and tries to scroll it wouldn't move. So I set an event to the labels that used the same method.

lbl.MouseDown += new MouseEventHandler(this.QuestionPanelMouseDown);
lbl.MouseMove += new MouseEventHandler(this.QuestionPanelMouseMove);

This made it scroll super fast when you click a label. To adjust for that I tried creating a new method for mouse move but changed the +5 and -5 to +1 and -1. It slowed it down but not enough. The locations are int's so I can't go any slower than +1 or -1.

I think the issue is related to the the location being sent it related to the label and not the panel itself but cant think of a way to actually solve for that.

Community
  • 1
  • 1
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Oct 17 '14 at 15:47
  • 1
    Wouldn't you be able to wrap an internal state machine based on a float value? Every time it occurs, just adjust the actual value by 1. – Kyle Baran Oct 17 '14 at 16:10
  • Kyle is right: keep state in floats, change those ints to float, add/subtract fractions and go back to int only when you do the actual movement! – TaW Oct 17 '14 at 16:38
  • Thats not really a fix for what I need. What I need it to do is act like I'm clicking the panel not the label. Otherwise I am still guessing to match the scroll speeds and in the end they are still going to be different because 1 will always be as slow is it can scroll. Also when scrolling after clicking a label moving the slightest bit causes it to move until you let go, while clicking the panel only does this if you move to the bottom of the panel. I want them to behave the same and like when I scroll after clicking the panel. – Cheap Funeral Oct 17 '14 at 19:47

1 Answers1

2

I found the answer after tons of searching. When using the code from the link I replaced off of the

e.Location

with

PointToClient(Cursor.Position)

so it looked like this.

Point mouseDownPoint;
private void innerpanel_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
        this.mouseDownPoint = PointToClient(Cursor.Position);
}

private void innerpanel_MouseMove(object sender, MouseEventArgs e)
{
    Point MouseLoc = PointToClient(Cursor.Position);
    if (e.Button != MouseButtons.Left)
        return;
    if ((mouseDownPoint.X == MouseLoc.X) && (mouseDownPoint.Y == MouseLoc.Y))
        return;

    Point currAutoS = innerpanel.AutoScrollPosition;
    if (mouseDownPoint.Y > MouseLoc.Y)
    {
        //finger slide UP
        if (currAutoS.Y != 0)
            currAutoS.Y = Math.Abs(currAutoS.Y) - 5;
    }
    else if (mouseDownPoint.Y < MouseLoc.Y)
    {
        //finger slide down
        currAutoS.Y = Math.Abs(currAutoS.Y) + 5;
    }
    else
    {
        currAutoS.Y = Math.Abs(currAutoS.Y);
    }

    if (mouseDownPoint.X > MouseLoc.X)
    {
        //finger slide left
        if (currAutoS.X != 0)
            currAutoS.X = Math.Abs(currAutoS.X) - 5;
    }
    else if (mouseDownPoint.X < MouseLoc.X)
    {
        //finger slide right
        currAutoS.X = Math.Abs(currAutoS.X) + 5;
    }
    else
    {
        currAutoS.X = Math.Abs(currAutoS.X);
    }
    innerpanel.AutoScrollPosition = currAutoS;
    mouseDownPoint = MouseLoc; //IMPORTANT

}

Then I made mouse down and mouse move events for everything inside the panel so no matter where you clicked it would scroll and at the same speed.